Precision Computing - Using PowerShell and PsExec to invoke expressions on remote computers
"While eagerly awaiting PowerShell’s upcoming remoting functionality, many people turn to Sysinternals’ PsExec tool to build their own version. However, PowerShell seems to hang when called via PsExec on the remote machine. This has come up on the SysInternal forum (http://forum.sysinternals.com/forum_posts.asp?TID=10823) among other places, and is caused by the same issue outlined here: http://www.leeholmes.com/blog/UsingMshexeInteractivelyFromWithinOtherPrograms.aspx.
To work around this problem, you can give some input to the Powershell process. But to give it input, you need to use cmd.exe:
psexec \\server cmd /c "echo . | powershell dir 'c:\program files'"
...
And to make it even more PowerShelly, the –OutputFormat of XML lets you get back an XML representation of your command’s output. On your local system, PowerShell converts your output back to deserialized objects. From there, you can continue to manipulate the output with the object-oriented goodness you’ve come to expect of us... "
I thought this was pretty darn cool. Cool enough that I immediately had to try it out... :)
In short, this post shows you how to use PsExec to run PowerShell on a remote computer returning the results to a local instance of PowerShell. (PsExec and PowerShell needs to be installed on the local machine and PowerShell on the remote machine).
Why would you want to do this?
I'm thinking aggregating information and/or doing stuff across a number of machines and providing centralized/combined results.
Hum... Now I'm thinking about all the cool stuff I can do with this... :)
No comments:
Post a Comment
NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...
ALL comments are moderated. I will review every comment before it will appear on the blog.
Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...
I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...
Please see my comment policy for more information if you are interested.
Thanks,
Greg
PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...