Home > Powershell, Toolbox > Last boot time with PowerShell

Last boot time with PowerShell

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:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.