Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 秒XXXXXXX.XXXXX:XXX的格式是什么(Win32\U网络登录配置文件)_C#_.net_Powershell - Fatal编程技术网

C# 秒XXXXXXX.XXXXX:XXX的格式是什么(Win32\U网络登录配置文件)

C# 秒XXXXXXX.XXXXX:XXX的格式是什么(Win32\U网络登录配置文件),c#,.net,powershell,C#,.net,Powershell,查询服务器上的WMi对象 $colItems = Get-WmiObject Win32_NetworkLoginProfile -Namespace "root\CIMV2" | Where-Object {$_.name -match "Name"} | Select-Object name,PasswordAge 根据MSDN 密码 数据类型:日期时间 访问类型:只读 密码生效的时间长度。此值根据自上次更改密码

查询服务器上的WMi对象

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

密码

数据类型:日期时间
访问类型:只读
密码生效的时间长度。此值根据自上次更改密码以来经过的秒数进行测量。
示例:00001201000230.000000000

我越来越

00000068235223.000000:000
所以我试着把它转换成
TimeSpan
DateTime
不走运。 冒号代表什么?如何获取它所代表的小时数


感谢将WMI类名添加到下一个被文档措辞弄糊涂的可怜灵魂的标题中


这就是有效的方法


这非常有效$str=“000000 68235223.000000:000” $ts=[System.Management.ManagementDateTimeConverter]::ToTimeSpan($str)

天数:68 小时:23 会议记录:52 秒:23 毫秒:0 滴答声:5961143000000 总天数:68.9947106481481 总小时数:1655.87305556 总分钟数:99352.3833333 总秒数:5961143
总计毫秒:5961143000

这是记录的DMTF时间间隔格式。基本上是字符串以
dddddddd hhmms.mmmmmm:000
的形式对时间跨度进行编码。请注意,对于时间间隔,结尾总是
:000

从文档中:

以下示例显示日期时间间隔的格式。 ddddddhhmms.mmmmmm:000
下表列出了日期时间间隔的字段。
字段说明
dddddddd表示天数的八位数字(00000000到9999999)。
HH一天中使用24小时时钟(00到23)的两位数小时。
毫米小时内的两位数分钟(00到59)。
SS一分钟内两位数的秒数(00到59)。
mmmmmm秒内的六位数微秒(000000到999999)

我相信文档对这个字段有点误导,因为它暗示整数是完整的秒,但实际上它是一种表示天、小时、分钟、秒等的字符串格式

您应该使用
[System.Management.ManagementDateTimeConverter]::ToTimeSpan
将此字符串转换为.NET Timespan,但是,无论出于何种原因,我实际收到的是一个数组,而不是一个用于密码的字符串,因此我必须使用此:

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

要添加到前面的所有答案中,从这种类型的字符串中生成内容的正确例程是call。这将生成一个
[System.TimeSpan]
对象,然后您可以用更好的方式解析它

课程转换的学分为。

这些是或。格式由WMI所基于的CIM标准定义

对于正常的datetime值,WMI对象提供了一个转换器函数。例如:

$_.ConvertToDateTime($_.PasswordExpires);
但这对间隔不起作用,这就是
PasswordAge
的含义

您指向的MS文档表示该值是秒数,但我相信这意味着精度是秒数,而不是秒数。例如,我目前的密码是43岁,如果是这样的话,那是不可能的。所以它必须使用区间格式

我会这样做:

$PasswordAge = New-TimeSpan -Days $_.PasswordAge.Substring(0,8) `
    -Hours $_.PasswordAge.Substring(8,2) `
    -Minutes $_.PasswordAge.Substring(10,2) `
    -Seconds $_.PasswordAge.Substring(12,2);
如果希望实际年龄值以小时表示,而不仅仅是时间跨度的小时值,请记住使用
$PasswordAge.TotalHours
,而不仅仅是
$PasswordAge.Hours

编辑:@Vesper是对的。您只需使用:

[System.Management.ManagementDateTimeConverter]::ToTimeSpan($_.PasswordAge);

密码的实际格式可能重复的是
“dddddd hhmmss.ffffff:000”
,即8位数的天,2位数的小时,分钟,秒,分数。他们说使用
[TimeSpan]::ParseExact($string,“dddddd hhmms.ffffff:000”,“$null)
,但我无法使它在我的PS4/Win7中工作。真的很奇怪。@Vesper:请看我下面的评论。我认为这只是措词不当——说它是从秒数来衡量的,而不是说它是秒数。关于日期时间格式而不是时间间隔有误导性。
[TimeSpan]:ParseExact($string,“dddddddd hhmmss.ffffff:000“,$null)
没有使用任何提供的字符串生成有效的时间间隔,而文档说应该生成。@Vesper:请参阅。正确的格式字符串应该是@“dddddd hhmmss\.ffffff\:\0\0\0”(注意:hh不是hh&转义所有未定义时间间隔说明符的值)。我在回答中会提到这一点,但是我的尝试总是收到一个错误,表示该值“超出有效值的范围”。它工作得非常好$str=“000000 68235223.000000:000”$ts=[System.Management.ManagementDateTimeConverter]::ToTimeSpan($str)$ts 12天:68小时:23分钟:52秒:23毫秒:0滴答声:5961143000000总计天:68.9947106481481总计小时:1655.8730555556总计分钟:99352.3833333总计秒:5961143总计毫秒:5961143000Ok出于某种原因
PasswordAge
对我来说是一个数组,不知道为什么,但它可以工作。