다음을 통해 공유


Date Time Conversion Using PowerShell

One my colleague asked me to help in Date and Time formatting in PowerShell.

He was trying to pull System Information report and end up with strange date and time format

Below is the code that my colleague was using,

$query="Select LastBootUpTime from Win32_OperatingSystem"

$boot=Get-WmiObject -query $query

$boot.LastBootUpTime

 Ended up with the below result.

20140408133745.125599+120
**
**All my report has the same output so need to get formatted date and time format

Try the below code

$query="Select LastBootUpTime from Win32_OperatingSystem"
$boot=Get-WmiObject -query $query
$boot.LastBootUpTime
[datetime]$boottime=$boot.ConvertToDateTime($boot.Lastbootuptime)

**
Tuesday, April 08, 2014 1:37:45 PM - Enjoy PowerShell :)**