Get-ADuser:无法识别搜索过滤器

希望你能够提供帮助 . 当我发出以下命令时:

$ g = get-ADGroupMember -Server sbintldirectory.com -Identity group1 $ n = get-ADGroupMember -Server ad.msdsprd.com -Identity group1 $ g.samaccountname |其中{$ n.samaccountname -notcontains $ psitem} | out-file c:\ temp \ new.txt $ users = gc C:\ Temp \ new.txt $ a = $ users | foreach {Get-ADuser -LDAPFilter“(samaccountname = $)" -Server dc:3268} $a | select samaccountname, distinguishedName | out-file c:\temp\list.txt $group = " CN = group1,OU = Testing,DC = domain,DC = com " get-content " c:\ temp \ list.txt”| ForEach { Get-ADuser -LDAPFilter "(samaccountname eq $_)" -Server dc:3268 | ForEach {Add-ADGroupMember -Identity $ group -Members $ .distinguishedName}}

结果:Get-ADuser:无法识别搜索过滤器在行:10 char:1 Get-ADuser -LDAPFilter“(samaccountname eq $ _)” - Server dc:3268 |佛... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~分类信息:未指定:(:) [Get-ADUser],ADException FullyQualifiedErrorId:搜索过滤器不能认可,Microsoft.ActiveDirectory.Management.Commands.GetADUser

非常感谢 .

回答(1)

2 years ago

您在此行上错误地使用 -LDAPFilter

Get-ADuser -LDAPFilter "(samaccountname=$_)" -Server dc:3268

-LDAPFilter 用于在LDAP语法中编写过滤器 .

您只是尝试获取特定用户,其中 $_ 已经代表用户名:

Get-ADuser -Identity $_ -Server dc:3268

有关属性的详细信息,请参阅the documentation on Get-ADUser .