The background: I’m a PoSH enthusiast, but far from being an expert. I have a very simple PS script I run against a server that returns to me the server name, OS, last reboot time and the presence of two patches (via Get-Hotfix -id KBxxxxxxx).
I’d now like to run this script against a very large number of servers, with the names contained in a text file. I’ve managed to accomplish this by way of a foreach loop, but it can take a very long time to serially query each server. I’d like to query each server in parallel which brings me to Jobs.
The question: I can start each job, but when I receive them, it’s full of a bunch of null values. I suspect this has to do with the script writing the information to the screen (lots of Write-Hosts going on), but I’m not sure how to go about fixing it. Can anyone give me a nudge in the right direction?
Without seeing the actual script it would be sophisticated guessing. Please post your code.
What I can tell already from your description - if you have a lot of Write-Host in it, you’re doing something wrong.
I’m away from my desk for a bit, but will post the code once I get back there. Basically, I declare a few variables, use a getWMI command using them and then write-host the results, if that’s any help.
There’s an old post of mine you may use as an inspiration. I’d bet it is slightly faster than your approach.
This old thing is missing the information about patches and has a lot of information you’re actually not interested in. So you should remove everything what’s not needed and add
Get-CimInstance Win32_QuickFixEngineering
to get the information about the patches you’re after.
The output is not as verbose as yours but I’d bet it’s going to be faster than yours even without adding a complexity level with using jobs. This way you can use the output an export it to a CSV file for later use for example or even pipe it to further cmdlets to filter only the desired information.