Working with dates

The WMI cmdlets do not convert date-time properties found in WMI. Querying the Win32_Process class for the creation date of a process returns the date-time property as a long string:

PS> Get-WmiObject Win32_Process -Filter "ProcessId=$PID" | Select-Object Name, CreationDate

Name CreationDate
---- ------------
powershell_ise.exe 20170209120229.941677+000

The .NET namespace used by the WMI cmdlet, System.Management, includes a class called ManagementDateTimeConverter, dedicated to converting date and time formats found in WMI.

The string in the preceding example may be converted, as follows:

Get-WmiObject Win32_Process -Filter "ProcessId=$PID" | 
    Select-Object Name, @{Name='CreationDate'; Expression={
[System.Management.ManagementDateTimeConverter]::ToDateTime($_.CreationDate)
}}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.83.150