问题
I tried with below script in local machine to run remote powershell script
which is located in remote azure vm
.
I'm able to connect to azure remote vm
through powershell pssession
, but Invoke-Command
is not returning anything. Unable to run remote powershell script
.
I tried as below aswell
But -FilePath
trying to look into local machine D:
drive instead of remote azure vm D:
drive.
How to run remote azure vm powershell script which is located in remote azure vm D:
drive
回答1:
My guess is that the fault probably lies in your GetRemoteAzureVMHstName.ps1
script.
make sure it's actually printing something.
回答2:
My script is working fine now.
In Invoke-Command
, for -Command
I removed single quotes for script file path and it worked.
Invoke-Command
should be as below
Invoke-Command -Session $s -Command { D:\User1\GetRemoteAzureVMHstName.ps1 }
instead of below
Invoke-Command -Session $s -Command { 'D:\User1\GetRemoteAzureVMHstName.ps1' }
来源:https://stackoverflow.com/questions/61032882/unable-to-run-remote-powershell-script-which-is-located-in-remote-azure-vm-d-dr