我正在尝试列出6个月以外尚未登录的所有帐户。

这是我第一次真正使用Powershell,此时我只是在编辑其他人的脚本以适合我自己的需求。

我想将搜索分为两个列表:仅计算机和仅用户。

六个月后的计算机代码。

Search-ADAccount -accountinactive -computersonly | where {$_.lastlogondate -lt (get-date).addmonths(-6)} | FT Name,LastLogonDate

为六个月后的用户提供代码。
Search-ADAccount -accountinactive -usersonly | where {$_.lastlogondate -lt (get-date).addmonths(-6)} | FT Name,LastLogonDate

但是,这些无效,只是吐出了所有帐户。我还注意到将-6更改为任何数字确实没有效果。
有什么建议吗?

最佳答案

您的测试正常(在我的广告中正常运行),唯一的问题是您必须消除$ _。laSTLogondate为null的对象。

尝试:

Search-ADAccount -accountinactive -usersonly  | where {! ($_.lastlogondate -lt (get-date).addMonths(-6))} | ft Name,lastlogondate

编辑:

由于lastLogon属性未在Active Directory中复制,因此可以在每个域 Controller 上的Active Directory副本中存储不同的值。一种解决方案是遍历所有域 Controller ,以建立此类用户的列表。但是我很确定还有其他解决方案!

关于powershell - Powershell列表无效帐户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10438304/

10-09 23:42