Why does PsExec hang after successfully running a powershell script?
Posted
by
Matt
on Server Fault
See other posts from Server Fault
or by Matt
Published on 2012-10-11T21:14:11Z
Indexed on
2012/10/11
21:38 UTC
Read the original article
Hit count: 264
powershell
|psexec
The script is fairly straight forward. Simply tries to start a bunch of windows services. Execution locally works fine when on the target machine. The script is actually executing fine as well when done via PsExec, it just never returns until I hit the "enter" key on my CMD prompt. This is a problem, because this is being called from TeamCity, and it makes the Agent hang waiting for PsExec to return.
I've tried the following:
- Adding an
exit
andexit 0
at the end of the Powershell script - Adding a
< NUL
to the end of the PsExec call, per the answer in this SF question - Adding a
>
stdout redirect
This is how I am actually calling psexec:
psexec \\target -u domain\username -p password powershell c:\path\script.ps1
No matter what I do, it hangs until I the locally on the cmd prompt. After I hit enter, I get the message:
powershell exited on target with error code 0.
© Server Fault or respective owner