是否可以在PowerShell中使用Invoke-Command
在遠程機器上運行腳本?如何在PowerShell中使用invoke-command在遠程機器上運行腳本
我曾嘗試:
Invoke-Command -ComputerName $MyPC -Credential $mycreds -ScriptBlock {
& "C:\Users\MyPC\Desktop\scripts\Script1.ps1"
}
返回
script1.ps1 is not recognized as the name of a cmdlet
這裏的情況是,我有一個遠程文件夾一些腳本,我需要使用Invoke-Command
或一些其他的方式來運行遠程機器上的腳本。
另外,如果我想要通過一些參數script1.ps1
如何寫?提前致謝!
剛剛使用'調用 - 命令 - 計算機名稱「服務器」-ScriptBlock {&「C:\ Users \ user \ Desktop \ 1.ps1「}'它對我來說工作得很好 - 如果你手動運行該腳本,它會工作嗎? – ConnorLSW