What is this format for seconds XXXXXXX.XXXXX: XXX (Win32_NetworkLoginProfile)

Request WMi for

$colItems = Get-WmiObject Win32_NetworkLoginProfile -Namespace "root\CIMV2" | Where-Object {$_.name -match "Name"} | Select-Object name,PasswordAge 

according to MSDN

Passwordage

Data type: datetime
Access Type: Read Only
Password expiration date. This value is measured from the number of seconds elapsed since the last password change.
Example: 00001201000230.000000 000

I get

 00000068235223.000000:000 

So, I tried to distinguish this from TimeSpan and DateTime out of luck. what the colon represents is how to get the number of hours it represents.


Thanks. Adding a WMI class name to the title for the next bad soul, which will be confused in the documentation.


that's what works

This worked perfectly $ str = "00000068235223.000000: 000" $ ts = [System.Management.ManagementDateTimeConverter] :: ToTimeSpan ($ str)

Days: 68 Work time: 23 Protocol: 52 Seconds: 23 Milliseconds: 0 Ticks: 59611430000000 Total days: 68.9947106481481 TotalHours: 1655.87305555556 TotalMinutes: 99352.3833333333 All seconds: 5961143 TotalMilliseconds: 5961143000

+7
c # powershell
source share
3 answers

This is the DMTF time slot format that is documented here . This is basically a string that encodes a time interval in the form ddddddddHHMMSS.mmmmmm:000 . Note that for time intervals, the ending is always :000 .

From the docs:

The following example shows the time interval format. ddddddddHHMMSS.mmmmmm: 000
The following table lists the fields for the date time interval. Field Description
dddddddd Eight digits that represent the number of days (from 00000000 to 99999999).
HH A two-digit hour of the day that uses a 24-hour clock (00 to 23).
MM Two-digit minute per hour (00 to 59).
SS Two-digit number of seconds per minute (00 to 59).
mmmmmm The six-digit number of microseconds in the second (from 000000 to 999999).

I find that the documentation is somewhat misleading for this field, as it implies that integers are full seconds, but in fact it is a string format representing days, hours, minutes, seconds, etc.

You should use [System.Management.ManagementDateTimeConverter]::ToTimeSpan to convert this string to .NET Timespan, however for some reason I actually got an array instead of a string for PasswordAge, so I had to use this:

 $p = gwmi Win32_NetworkLoginProfile [System.Management.ManagementDateTimeConverter]::ToTimeSpan($p.PasswordAge[1]) 
+5
source share

To add to all the previous answers, the correct procedure to make something out of this type of string is to call [System.Management.ManagementDateTimeConverter]::ToTimeSpan($string) . This will create a [System.TimeSpan] object that you can better analyze.

Credit for class conversion for this .

+4
source share

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); 
+1
source share

All Articles