首页 > 解决方案 > 使用 msDS-cloudExtensionAttribute20 获取 ADUser 过滤器参数

问题描述

我想用 Get-ADUser 过滤一些条件来获取用户,因为我在 msDS-cloudExtensionAttribute20 (eg Email address)中输入了一些与 UserPrincipalName 相同的值,当我运行此代码时它没有显示任何错误但没有工作中,如何解决这个问题,请帮助

谢谢

$msDS = "msDS-cloudExtensionAttribute20"  
get-aduser -filter {(Enabled -eq $true) -and (UserPrincipalName -eq '$msDS')} -SearchBase 'OU="",OU="",OU="" ,DC=""' -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress,"msDS-cloudExtensionAttribute20",UserPrincipalName | where { $_.passwordexpired -eq $false }

标签: powershellactive-directory

解决方案


LDAP的查询过滤器语法不支持以您希望的方式跨多个属性进行任意比较(尽管那会很酷!) - 您需要查询所有可能的用户并使用 PowerShell 在客户端过滤它们:

Get-ADUser -Filter {Enabled -eq $true} -SearchBase 'OU="",OU="",OU="" ,DC=""' -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress,"msDS-cloudExtensionAttribute20",UserPrincipalName | Where-Object {
    $_.passwordexpired -eq $false -and $_.'msDS-cloudExtensionAttribute20' -eq $_.UserPrincipalName
}

推荐阅读