Speeding Up Remote Inventory

by Dec 29, 2009

Get-WMIObject is a fantastic cmdlet to query information locally and on remote systems. Have a look:

Get-Content c:\management.txt |
ForEach-Object {
Get-WmiObject Win32_BIOS -ComputerName $_
}

Here, Get-WMIObject contacts all machines listed in the file management.txt and returns BIOS information. You could also query for just any WMI class this way.

Unfortunately, this approach may take a long time since processing is sequentially, especially when systems are offline. In PowerShell v.2, simply run it as separate background jobs. This way, PowerShell processes all queries simultaneously, and your console is not blocked. Just add the -asJob switch parameter:

Get-Content c:\management.txt |
ForEach-Object {
Get-WmiObject Win32_BIOS -ComputerName $_ -asJob
}

Run Get-Job to check for results, and run Receive-Job to retrieve the information gathered by the background jobs.

One important thing to note: Background jobs require PowerShell v.2, and they also require remote setup. Even though a standalone Get-WMIObject cmdlet does not require remote setup when using -computername, it *is* required when running as background job. So, all remote machines must also use PowerShell v.2 and be configured to work remotely.

Twitter This Tip! ReTweet this Tip!