问题
Trying to execute ps script on azure vm's using azure automation using the approach defined at https://stackoverflow.com/a/62258063/1014275. Script below does copy files between azure vm's. Both Vm's are in same subnet and if we run the copy-item command from VM powershell it copies the files to target VM folder. The same script executes successfully with azure automation runbooks, but without copying files.
Script used:
Copy-Item -Path C:\folder\sample.txt -Destination \\\VmHostname\C$\folder -Force
Updated 1: The script throws exception as below.
Failed
VERBOSE: Performing the operation "Copy File" on target "Item: C:\folder\file.txt Destination:
\\vmhostname\C$\folder". Copy-Item : You can't connect to the file share because it's not secure. This share requires the obsolete SMB1
protocol, which is unsafe and could expose your system to attack.
Your system requires SMB2 or higher.
Update 2:
run the below ps command (Solved update 1 issue)
Enable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
after this we are getting below error
Failed
Copy-Item : Access is denied
At C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.5\Downloads\script17.ps1:1 char:1
+ Copy-Item -Path C:\folder\file.txt -Destination \\vmhostname ...
Any suggestion would be helpful!
来源:https://stackoverflow.com/questions/62260399/powershell-copy-item-not-working-with-azure-automation