首页 > 解决方案 > 使用 powershell 按“城市”和“成员”组过滤的广告用户

问题描述

我们开始升级我们的 Citrix 平台,我正在尝试使用 AD 来获取当前在特定站点以及使用我们的 Citrix 环境的用户列表。我目前有以下内容来过滤网站并删除任何离开者等:

Get-ADUser -Filter 'City -Like "Portsmouth" -and Description -notlike "LEAVER*" -and Description -notlike "This user was*"' | select-object name, userprincipalname | format-table

这很好用,但是我现在只需要按我们的 Citrix 'Member of' 组中的人进行过滤。我相信我可以自己使用以下内容:

Get-ADGroupMember 'Citrix_USR'

但是,我正在努力寻找一种方法将其添加到我之前的搜索中并使其正常工作。任何帮助或指出我正确的方向都会很棒。

PS这是我第一次发帖,请多多关照,哈哈。

标签: powershell

解决方案


Where-Object您可以使用cmdlet 对MemberOf属性执行筛选。

确保使用Get-ADUsercmdlet指定请求的属性-Properties MemberOf-Properties *

像这样:

#first you get distinguished name
$dn = Get-ADGroup 'Citrix_USR' | Select -ExpandProperty DistinguishedName
#now you perform filtering
Get-ADUser -Filter 'City -Like "Portsmouth" -and Description -notlike "LEAVER*" -and Description -notlike "This user was*"' -Properties MemberOf | Where-Object {$_.MemberOf.Contains($dn)} | Select-Object name, userprincipalname | Format-Table

推荐阅读