PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Scripts

09-19-2015 - Bryan's Games Galore!
09-18-2015 - Bryan's Process Help
09-06-2015 - Bryan's Wifi Pinger

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Getting Last Bootup Time

In PowerShell 3.0 and better, it's trivial to get back real DateTime information from WMI using Get-CimInstance. This would tell you when your system was last booted:

#requires -Version 3 
(Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime 

In PowerShell 2.0, your only choice is Get-WmiObject which reports the information in internal WMI format:

(Get-WmiObject -Class Win32_OperatingSystem).LastBootUpTime 

Here, you would have to convert the WMI format manually:

$object = Get-WmiObject -Class Win32_OperatingSystem
$lastboot = $object.LastBootUpTime

The ConvertToDateTime() conversion method is actually an attached method. Behind the scenes, it is a static method call that does the job:

$object = Get-WmiObject -Class Win32_OperatingSystem
$lastboot = $object.LastBootUpTime

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.