2013-07-29 49 views
1

我正在運行下面的批處理文件來連接遠程計算機&使用psexec在遠程計算機上運行powershell腳本。使用Psexec運行powershell腳本時出錯

運行本地機(myscript.bat)
運行命令的批處理文件:myscript.bat \\ mymachine上

set machinename=%1 

@echo " started" 
PsExec.exe %machinename% -u myID -p myPwd -i -d cmd /c mkdir C:\test 

xcopy DirChk.ps1 %machinename%\C$\test 

psexec.exe %machinename% -u myID -p myPwd cmd.exe /c 'echo .|powershell.exe -file C:\Test\DirChk.ps1' 

@echo "Completed" 

錯誤:

Starting PsExec service on \\mymachine ...Processing -File 'C:\Test\DirChk.ps1'' failed because the file does not have a '.ps1' extension. Specify a valid PowerShell script file name, and then try again.

+0

你可以使用PowerShell遠程而不是'psexec'? – alroc

回答

3

嘗試雙引號。批處理文件由CMD,不明白單引號解釋。這應該工作:

psexec.exe %machinename% -u myID -p myPwd cmd.exe /c "echo .|powershell.exe -file C:\Test\DirChk.ps1"