Unable to run remote powershell script which is located in remote Azure VM D: drive using Invoke-Command

谁说胖子不能爱 提交于 2020-04-16 05:48:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!