Here's another handy and simple function which lets you query a bunch of servers at once to find out when they were last rebooted. It's taking advantage of
Get-WmiObject and the
root\civ2\Win32_OperatingSystem class. For maximum parallelization, I've forced pipeline usage to first colapse the process block into a single array to create only one Get-WmiObject call. This is significantly faster than the default pipeline behavior which is sequential, with 1000 servers completing under a minute (local LAN) vs sequential calls taking close to 10 minutes.
Here's it in action:
PS C:\> Get-Content .\serverlist.txt | Get-LastBootTime
Name UpSince
---- -------
NOTSERVER Unknown
SERVER001 6/20/2015 10:46:25 PM
SERVER002 6/20/2015 10:26:24 PM
SERVER003 6/20/2015 10:30:17 PM
SERVER004 6/20/2015 10:27:52 PM
SERVER005 6/20/2015 10:38:27 PM
SERVER006 6/20/2015 10:30:12 PM
SERVER007 6/20/2015 11:54:01 PM
SERVER008 6/20/2015 10:28:39 PM
SERVER009 6/20/2015 10:26:15 PM
SERVER010 6/20/2015 10:27:01 PM
Source Code:
No comments:
Post a Comment