I have a powershell command which runs in TeamCity. When I try to run a batch file remotely using psexec from this .ps file, I see once the remote execution started, nothing happens. I tried several ways discussed in multiple forums but of no use.
Main.ps
:
Invoke-Command -ScriptBlock {C:\PSInstall.bat}
PSInstall.bat
:
C:\Tools\psexec.exe -i -d "\\server2" -u "domain\admin" -p "abcd" -f -w cmd "C:\Install.bat"
My Build log:
[11:32:02]C:\BuildAgent\work\603cfc01a3fe22bb\Tools>C:\Tools\psexec.exe -i -d "\\server2" -u "domain\admin" -p "abcd" -f -w cmd "C:\Install.bat"
[11:32:02]
[11:32:02]PsExec v1.98 - Execute processes remotely
[11:32:02]Copyright (C) 2001-2010 Mark Russinovich
[11:32:02]PsExec executes a program on a remote system, where remotely executed console
[11:32:02]Sysinternals - www.sysinternals.com
[11:32:02]applications execute interactively.
I am stuck at this point with no clue what's happening, any help is highly appreciated. I have set EULA already on the remote machine.
The
PsExec
command/arguments you have given in your example are malformed, instead try:Also, putting it all together with an example adapted from something I've written earlier.
PSExecRetry.log
will contain the output ofPsExec
(including errors), although won't capture theStdOut/StdErr
output of the subsequent command as-is.PSExecRetry.ps1
is the PowerShell script with some basic retry logic:PSInstall.cmd
is modified as follows:Install.bat
stub: