我有一个包含过期元素以及其他属性的 XML 文件。我必须解析文件并通过 Powershell 脚本找出在未来 50 天内到期的所有元素。
XML 文件中的条目:
<Certificate>
<Version>3</Version>
<SignatureAlgorithm>sha1RSA</SignatureAlgorithm>
<Subject />
<NotAfter>2017-07-12T09:19:44Z</NotAfter>
<NotBefore>2016-07-12T09:19:44Z</NotBefore>
<IsVerified>true</IsVerified>
</Certificate>
现在通过Powershell,我正在尝试做这样的事情:
$ExpiryDate=(GET-DATE).AddDays(50)
$xdoc = [xml] (get-content $InputFile)
$xdoc.SelectNodes("//Certificate/NotAfter[. > $ExpiryDate]")
#$xdoc.Save($ResultsFile)
但这似乎不起作用。我什至不确定是否需要将“NotAfter”字段作为日期或字符串进行比较。任何指针都会有很大帮助。