Archive

Archive for November, 2012

Last boot time with PowerShell

November 14th, 2012 No comments

Has to retrieve a bunch of boot times for a list of servers – quickly put together a function (I know there are many equally easy ways – but felt like retrieving info via PowerShell as part of a bigger report)

Function get-lastboot { 
 param($computername)
$date = Get-WmiObject Win32_OperatingSystem -ComputerName $computername | foreach{$_.LastBootUpTime}
$RebootTime = [System.DateTime]::ParseExact($date.split('.')[0],'yyyyMMddHHmmss',$null) 
$RebootTime

} #end function

Like so:

PS C:\scripts\Powershell> get-lastboot winhost7

20 October 2012 20:20:11
Categories: Powershell, Toolbox Tags: