I need to run PS script in Azure Runbook to map a drive to a remote server to then copy very specific files to Azure blob storage.
NOTE: The entire script works 100% in VSCode > Automation Runbook. It completes all steps as intended. However, when I publish the script and run the Runbook in the Portal the code to map a drive fails and therefore does not copy the files to blob storage. Overall, I need to ‘get-childitem’ to copy (servershare**.bak) all subfolders to then copy specific files based in ‘lastwritetime’ because there are multiple files in the dir with same *.bak to their respective folder name in blob.
I’m open to suggestions if anyone has any and really appreciate the help in advance!
Here is the work performed to ensure PS remoting is enabled on remote Server.
- Enable-PSRemoting -Force
- Get-NetFirewallRule -Name ‘WINRM*’ | Select-Object -Property Name
- Enable-PSRemoting -SkipNetworkProfileCheck -Force
- Set-NetFirewallRule -Name ‘WINRM-HTTP-In-TCP’ -RemoteAddress Any
- restarted winrm service
- Disabled remote server Firewall (to test)
The following was run on my local computer and also run in runbook which does look to have run successfully. - Set-Item WSMan:localhostClientTrustedHosts -Value ” -Concatenate
- My domainusername is member of Local Admin group on Remote Server
All the following snippets work in my VSCode Azure Automation Runbook but does NOT work in the actual Azure Runbook.
snippet 1 to map drive result: The network path was not found.
New-PSDrive -Name Y -PSProvider FileSystem -Root $Source_Folder -Credential $Credentials -Scope Global
snippet 2 to map drive result: Access is denied. Connecting to remote server ihsql20a failed with the following error message : The WinRM client cannot process the request.
NOTE: The Server is on the same Domain and I have administrator and domain admin access.
Set-Item WSMan:localhostClientTrustedHosts -Value ‘remote server IP’ -Concatenate -Force
Invoke-Command -ComputerName “” {New-PSDrive -Name Y -PSProvider FileSystem -Root “servernameshare” -Credential $Credentials -Scope Global}
snippet 3 to map drive result: The network path was not found.
New-SmbMapping -LocalPath “W:” -RemotePath “\share” -UserName “domainusername” -Password “” -Persistent $true
snippet 4 to map drive result: System error 53 has occurred. The network path was not found.
Net Use Y: ihe-sql20pTest /user:domainusername password /persistent:yes