1
我試圖在PowerShell腳本中遠程執行.bat文件。在我的腳本文件中的代碼看起來是這樣的:在PS會話期間執行.cmd文件時出錯
$server
$cred
# Both of these methods are strings pointing to the location of the scripts on the
# remote server ie. C:\Scripts\remoteMethod.cmd
$method1
$method2
$scriptArg
Enter-PSSession $server -Credential $cred
Invoke-Command {&$method1}
if($?)
{
Invoke-Command {&$method2 $args} -ArgumentList $scriptArg
}
Exit-PSSession
但每當我運行它,我得到
術語「C:\腳本\ remoteMethod.cmd」沒有被識別爲名稱一個cmdlet,函數,腳本文件或可操作的程序。檢查名稱的拼寫,或者如果包含路徑,請驗證路徑是否正確,然後重試。
出現這種情況,即使我身邊,我發現這個問題Using Powershell's Invoke-Command to call a batch file with arguments並試圖接受的答案無濟於事方法被調用的順序。
切換。
謝謝,這似乎已經做到了。現在它工作正常 – winthethird