質問

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