【发布时间】:2019-12-23 20:57:33
【问题描述】:
我正在使用 Search-ADAccount 从 Active Directory 获取非活动用户列表,然后将其传送到 Get-ADUser,以便我可以使用 MemberOf 不包含组 "Accounts_to_Keep" 的位置。我相信我可以使用正确的号码 (379) 和完整的 DN 字符串。但是,如果组移动,我想使用-match 或-like 来仅使用组的名称。它返回的数字不一样。
如果我使用MemberOf 对单个用户单独执行此操作,它只会过滤掉一个组并返回用户拥有的另一个组,所以我认为这就是为什么我拥有的不仅仅是-contains。有没有办法在没有foreach自己的情况下使用-like 或-match 作为子数组?
从字符串中删除完整的 DN
PS> $InactiveAll.Count
488
PS> ($InactiveAll | Where {-not $_.memberof.contains("CN=Accounts_to_Keep,OU=DC")}).Count
379
PS> ($InactiveAll | Where { $_.memberof -notlike "*Accounts_To_keep*"}).Count
427
PS> ($InactiveAll | Where {-not $_.memberof -contains ("CN=Accounts_to_Keep,OU=DC")}).Count
61
PS> ($InactiveAll | Where {-not ($_.memberof -contains ("CN=Accounts_to_Keep,OU=DC"))}).Count
379
PS> ($InactiveAll | Where { $_.memberof -notmatch "Accounts_To_Keep"}).Count
427
【问题讨论】:
标签: powershell active-directory operators contains group-membership