简体   繁体   English

从有效日期开始计算AD密码的年龄

[英]Calculate AD password age from expiration date Powershell

I want to calculate the age of the password, in days, using the PasswordLastSet property. 我想使用PasswordLastSet属性以天为单位计算密码的使用期限。 I've created the below code but Password Age never outputs anything. 我创建了以下代码,但是密码时代从未输出任何信息。 I'm guessing there is a type error but I'm not sure how to convert to DateTime. 我猜有类型错误,但是我不确定如何转换为DateTime。 Any thoughts? 有什么想法吗?

Get-ADComputer myComputer -Properties PasswordLastSet | Select-Object -Property PasswordLastSet, @{Name = 'Password Age';Expression = {Get-Date - ([datetime]($_.PasswordLastSet))}}

The reason for the failure is the lack of parens around the Get-Date call. 失败的原因是Get-Date调用周围缺少括号。 Without those parens, the cmdlet tries to use the remainder of the line as input ... [ grin ] wrapping the cmdlet in parens - (Get-Date) - forces the cmdlet to run without trying to parse the remainder of the line. 如果没有这些括号,则cmdlet尝试将行的其余部分用作输入... [ 咧嘴笑 ]将cmdlet包裹在括号中- (Get-Date) -强制cmdlet运行而不尝试解析行的其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM