问题描述
在查询一个WMI对象
$colItems = Get-WmiObject Win32_NetworkLoginProfile -Namespace "root\CIMV2"
| Where-Object {$_.name -match "Name"} | Select-Object name,PasswordAge
根据MSDN
according to MSDN
PasswordAge
数据类型:日期时间
访问类型:只读
时间长度的密码已生效。这个值是从距今已有密码上次更改秒的数量来衡量。
示例:00001201000230.000000 000
Data type: datetime
Access type: Read-only
Length of time a password has been in effect. This value is measured from the number of seconds elapsed since the password was last changed.
Example: 00001201000230.000000 000
我收到
00000068235223.000000:000
所以,我试图铸造这时间跨度
和的DateTime
没有运气。什么是结肠再度present如何得到数个小时就重新present。
So I have tried casting this to TimeSpan
and DateTime
no luck.what does the colon represent how to get number hours it represent.
由于添加WMI类名的标题下一个可怜的灵魂,获得由文件措辞混淆。
Thanks Adding the WMI class name to title for the next poor soul that get confused by documentation wording.
这里是什么工作
这是完美工作$海峡=00000068235223.000000:000$ TS = [System.Management.ManagementDateTimeConverter] :: ToTimeSpan($ STR)
That worked perfectly $str = "00000068235223.000000:000"$ts = [System.Management.ManagementDateTimeConverter]::ToTimeSpan($str)
天数:68时间:23分:52秒:23毫秒:0蜱:596114.3亿TotalDays:68.9947106481481TotalHours:1655.87305555556TotalMinutes:99352.3833333333TotalSeconds:5961143TotalMilliseconds:5961143000
Days : 68Hours : 23Minutes : 52Seconds : 23Milliseconds : 0Ticks : 59611430000000TotalDays : 68.9947106481481TotalHours : 1655.87305555556TotalMinutes : 99352.3833333333TotalSeconds : 5961143TotalMilliseconds : 5961143000
推荐答案
这是该记录的。基本上它是字符串连接codeS的时间跨度的形式 ddddddddHHMMSS.mmmmmm:000
。请注意,对于时间间隔,结局总是:000
This is the DMTF time interval format which is documented here. Basically it is string that encodes a time span in the form ddddddddHHMMSS.mmmmmm:000
. Note that for time intervals, the ending is always :000
.
从文档:
下面的例子显示了一个日期 - 时间间隔的格式。 ddddddddHHMMSS.mmmmmm:000
下表列出了日期时间间隔的字段。
字段说明
DDDDDDDD八位数字的重新present天数(00000000通过99999999)。
HH两位数小时,使用24小时时钟(00至23)的一天。
MM两位数分钟的小时(00至59)。
SS两位数的秒分钟(00至59)的数量。
MMMMMM六位数在第二(000000通过999999)微秒数。
我相信文档是这个领域有些误导,因为它意味着整个数字都充满秒,但实际上它是一个字符串格式重新presenting日,时,分,秒等。
I believe the documentation is somewhat misleading for this field, since it is implying the whole numbers are full seconds, but in fact it is a string format representing days, hours, minutes, seconds, etc.
您应该使用 [System.Management.ManagementDateTimeConverter] :: ToTimeSpan
来然而,这个字符串转换为一个.NET时间跨度,因为我实际收到的阵列,而不是无论什么原因一个字符串PasswordAge,所以我只好用这样的:
You should use [System.Management.ManagementDateTimeConverter]::ToTimeSpan
to convert this string to a .NET Timespan, however, for whatever reason I actually received 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])
这篇关于这是什么格式秒XXXXXXX.XXXXX:XXX(Win32_NetworkLoginProfile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!