PS
Powershell Tutorial Online


Conversion dates WMI size

How to convert a date in WMI format deviation [datetime] and vice-versa
Let me tell you how we can convert these dates when WMI queries that return a date.
The date format used by WMI is the standardized DMTF size.

PS> (Get-WmiObject-class Cim_OperatingSystem).InstallDate
20080618021130.000000 +120
The result is a relatively easy to interpret dates. We can easily cut into small pieces and reformat a date in a expected format in PowerShell.

Here dotnet framework class come and rescue you System.Management.ManagementDateTimeConverter. Class does includes ToDateTime and method

PS> $ DateInstallation = (Get-WmiObject-class Cim_OperatingSystem). InstallDate
PS> [System.Management.ManagementDateTimeConverter] :: ToDateTime ($ DateInstallation)

Wednesday, Jun 18, 2008 2:11:30 a.m.

How to get current datetime

PS> $ DateHeureCourante = Get-Date