Beginning Parallel Processing in PowerShell

Here’s a template (of sorts) that should be fairly easy to modify to suit your own needs, that solves the dilemma of running a command across multiple systems and having to wait for each one to finish before moving onto the next. This is particularly problematic when running WMI commands which takes 2-10 seconds per device to return results.  This script, in theory could be used to run the command on all servers at the same time – quite the time saver.

The example below takes a network address (eg: 10.50.18.0) and pings all devices from .1 through to .254 (with each being pinged in its own parallel thread).

You could change this to be a group of Active Directory Computers, or well, any array of objects; and run commands against all of them in parallel.

NOTE: Even though we’re incrementing through the host addresses from 1 to 254, the parallel nature of what we’re doing means that some threads will likely finish out of order, and the results you get back will be somewhat random. IE; you could get results for 10.50.18.220 before 10.50.18.219 is returned.

And I’ve also included a progress bar, because, why not.

 

The result will be a list of IP addresses that were successfully pinged, displayed to the screen:

 

Leave a Reply

Your email address will not be published. Required fields are marked *