1
我有一個重複使用的腳本,我一直在成功調用遠程ps1文件,但現在我試圖調用遠程批處理文件,我得到了以下錯誤消息 -powershell - Invoke-Command:FilePath參數的值必須是Windows PowerShell腳本文件
Invoke-Command : The value of the FilePath parameter must be a Windows
PowerShell script file. Enter the path to a file with a .ps1 file name
extension and try the command again.
這是腳本 -
#Admin Account
$AdminUser = "domain\svc_account"
$Password = Get-Content D:\scripts\pass\crd-appacct.txt | convertto-securestring
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminUser, $Password
$FileName = "runme.bat"
$ItemLocation = "D:\path\to\bat\"
#Invoke Script Remotely
Invoke-Command -ComputerName Servername -filepath "$ItemLocation$FileName" -Authentication CredSSP -Credential $Credential
'位於本地計算機上.bat'文件,你要調用它的遠程計算機上? – PetSerAl
@PetSerAl bat文件是遠程的。 – whoisearth
使用'-ScriptBlock'而不是'-FilePath':'Invoke-Command -ScriptBlock {&「$ using:ItemLocation $ using:FileName」} ...'。 – PetSerAl