Many PowerShell commands offer the ability to run against a remote computer.  If not, PowerShell remoting can help (Helpful resources from Ravikanth Chaganti and Dr. Tobias Weltner / Don Jones).  If you don’t have PowerShell remoting set up across your enterprise, I would recommend looking into it.  More details on executing processes through PowerShell can be found here.

So!  Perhaps you have a command you want to run against a remote system on a domain, and little has been set up apart from standard administrative shares.  One option would be to create the process on the remote system via WMI, save the data on that remote system, and pull the data to your local system for processing.

The other day I was pining for the ability to run netstat remotely.  Shay Levy has a nice script that parses netstat -ano text results into a PSCustomObject that you can actually work with.  He added PID to process name conversions, and filters to return specific processes, addresses, ports, states, and protocols.  This is quite handy as is, but wouldn’t it be great to run against a remote computer?

It turns out someone had done this; The One True Chris posted a script that creates the process on the remote system via WMI and pulls the data back in to your local system.  Unfortunately, this simply returns raw text, limiting your ability to work with the data.

I managed to butcher the code behind each of these functions to create a hybrid.  With this, you can specify a remote system and netstat runs on that system.  The results are retrieved and processed with Shay’s code to produce netstat data in object form.

Getting Started

The function can be found here.  Keep in mind you will need appropriate access to create a process with WMI and connect to the administrative share for remote systems.


Please go easy on me : )  This is the first code I’m posting publicly, and it certainly isn’t pretty!  Feel free to use and modify this as needed, and let me know if you run into any issues!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s