【发布时间】:2012-12-10 17:46:33
【问题描述】:
我正在尝试编写一个 PowerShell 脚本,该脚本将查找 AD 中六个月未登录的所有用户,并且不包括 Terminated Users OU 或 Terminated Users\vendors and others OU 中的任何人。我似乎无法排除任何一个 OU。搜索的六个月部分完美运行。
这是我当前的代码:
Search-ADAccount -accountinactive -datetime (get-date).AddMonths(-6) -usersonly | ft Name,LastLogonDate | ? {$_.DistinguishedName -notlike "*ou=Terminated Users,*" -and $_.DistinguishedName -notlike "*ou=vendors and others,*"} | Out-File stale_users.txt
我已经从 OU 名称的末尾删除了 ,*,尝试了 -or,并且只尝试了每个 OU。它仍然不会跳过搜索那些 OU。
【问题讨论】:
标签: powershell search ou