Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "samaccountname", "PasswordNeverExpires", "PasswordLastSet", "PasswordExpired", "GivenName", "SurName", "EmailAddress", "lastlogon", "msDS-UserPasswordExpiryTimeComputed" | Select-Object -Property "Displayname", "samaccountname", "PasswordNeverExpires", "PasswordLastSet", "PasswordExpired", "GivenName", "SurName", "EmailAddress", "LastLogon", "msDS-UserPasswordExpiryTimeComputed",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed").ToShortDateString()}} | Where {($_.ExpiryDate -le $date.adddays(14).ToShortDateString()) -and ($_.ExpiryDate -ge $date.adddays(0).ToShortDateString())}
这是一个截图,它是为到期日期输出的。它不应该超过3/03/22,但我看到的是3月14日。我不知道为什么没有正确地应用Where约束。
`Get-ADUser
-filter {Enabled -eq $True -and PasswordNeverExpires -eq $False}
–Properties "DisplayName", "samaccountname", "PasswordNeverExpires", "PasswordLastSet", "PasswordExpired", "GivenName", "SurName", "EmailAddress", "lastlogon", "msDS-UserPasswordExpiryTimeComputed"
| Select-Object -Property "Displayname", "samaccountname", "PasswordNeverExpires", "PasswordLastSet", "PasswordExpired", "GivenName", "SurName", "EmailAddress", "LastLogon", "msDS-UserPasswordExpiryTimeComputed",
@{Name="ExpiryDate";
Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
| Where {($_.ExpiryDate -le $date.adddays(14))
-and ($_.ExpiryDate -ge $date.adddays(0))}`
按照Theo关于不使用字符串比较的建议,该命令按预期的方式工作。非常感谢西奥。
发布于 2022-03-07 18:00:50
由于在我的帖子下面的评论,我能够纠正这个查询并使它正常工作。
转换为字符串的原因是,当我从ADUser中提取到期日期时,它是使用以FileTime格式出现的,当时我不确定如何处理它,所以我已经将它转换为DateTime。然后到了一根绳子,认为这会更容易处理。西奥指出的情况并非如此。
我也继续问我的问题,但并不是所有的问题都在同一条线上。
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and samaccountname -notlike 'iss*'}`
–Properties "DisplayName", "samaccountname", "PasswordNeverExpires", "PasswordLastSet", "PasswordExpired", "GivenName", `
"SurName", "EmailAddress", "lastlogon", "Department", "msDS-UserPasswordExpiryTimeComputed" `
| Select-Object -Property "Displayname", "samaccountname", "PasswordNeverExpires", "PasswordLastSet", "PasswordExpired", "GivenName", "SurName", `
"EmailAddress", "LastLogon", "Department", "msDS-UserPasswordExpiryTimeComputed",@{Name="ExpiryDate";`
Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} `//this was the location of the initial conversion to String that led me to think to the conversion had to take place
| Where {($_.ExpiryDate -le $date.adddays(14)) -and ($_.ExpiryDate -ge $date.adddays(0))} `
虽然这里的翻译还不太好。
https://stackoverflow.com/questions/71161894
复制相似问题