문제

I am running the below batch file to connect the remote machine & run a powershell script on the remote machine using psexec.

Running batch file on local machine (myscript.bat)
Running Command: 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"

Error:

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.

도움이 되었습니까?

해결책

Try double quotes. Batch files are interpreted by cmd, which doesn't understand single quotes. This should work:

psexec.exe %machinename% -u myID -p myPwd cmd.exe /c "echo .|powershell.exe -file C:\Test\DirChk.ps1"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top