提问人:Chrismage 提问时间:8/10/2017 最后编辑:John SaundersChrismage 更新时间:4/8/2021 访问量:111188
PowerShell 中的 LDAP 查询
LDAP query in PowerShell
问:
我尝试在PowerShell中运行以下查询,但没有成功:(
((mailNickname=id*)(whenChanged>=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl)(memberof=CN=VPN-2,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl))
答:
12赞
Mathias R. Jessen
8/10/2017
#1
鉴于查询筛选器的内容,我会说您正在寻找用户,因此我建议使用 ActiveDirectory RSAT 模块中的 cmdlet:Get-ADUser
Get-ADUser -LDAPFilter '((mailNickname=id*)(whenChanged>=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl)(memberof=CN=VPN-2,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl))'
21赞
iRon
8/10/2017
#2
不带 cmdlet(ActiveDirectory RSAT 模块):Get-ADUser
$Filter = "((mailNickname=id*)(whenChanged>=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl)(memberof=CN=VPN-2,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl))"
$RootOU = "OU=01,DC=em,DC=pl,DC=ad,DC=mnl"
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$($RootOU)")
$Searcher.Filter = $Filter
$Searcher.SearchScope = $Scope # Either: "Base", "OneLevel" or "Subtree"
$Searcher.FindAll()
评论
1赞
Ben
12/1/2020
我必须向 DirectoryEntry 构造函数的第一个参数添加主机名,并将用户名和密码添加为第二个和第三个参数,才能正常工作。但这是正确的方法,谢谢!
评论
userAccountControl