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

时间:2014-12-18 23:53:36

标签: variables powershell foreach filter

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

$ 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 |选择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 |佛... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo:NotSpecified:(:) [Get-ADUser],ADException     + FullyQualifiedErrorId:无法识别搜索过滤器,Microsoft.ActiveDirectory.Management.Commands.GetADUser

非常感谢。

1 个答案:

答案 0 :(得分:2)

您在此行中未正确使用-LDAPFilter

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

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

您只是想要获得特定用户,其中$_已经代表用户名:

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

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