These are CIM_DATETIME values or interval values . The format is determined by the CIM standard on which WMI is built.
With normal date and time values, the WMI object provides a converter function. For example:
$_.ConvertToDateTime($_.PasswordExpires);
But this does not work for intervals, which is PasswordAge .
In the MS document, you indicate that the value is the number of seconds, but I believe that this means the accuracy of the second , not literally in seconds . My current password says that 43 years old, if it is, for example, and it is impossible. Therefore, it should use the Interval format.
I would do this:
$PasswordAge = New-TimeSpan -Days $_.PasswordAge.Substring(0,8) ` -Hours $_.PasswordAge.Substring(8,2) ` -Minutes $_.PasswordAge.Substring(10,2) ` -Seconds $_.PasswordAge.Substring(12,2);
Remember to use $PasswordAge.TotalHours , not just $PasswordAge.Hours if you want the actual age value to be expressed in hours, not just the hourly time value.
Edit: @Vesper is right. You can simply use:
[System.Management.ManagementDateTimeConverter]::ToTimeSpan($_.PasswordAge);
Bacon bits
source share