gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:16:49 24 4
gpt4 key购买 nike

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

$g = get-ADGroupMember -Server sbintldirectory.com -Identity group1
$n = get-ADGroupMember -Server ad.msdsprd.com -Identity group1
$g.samaccountname | where {$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 : The search filter cannot be recognized
At line:10 char:1
+ Get-ADuser -LDAPFilter "(samaccountname eq $_)" -Server dc:3268 | Fo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException
+ FullyQualifiedErrorId : The search filter cannot be recognized,Microsoft.ActiveDirectory.Management.Commands.GetADUser

非常感谢。

最佳答案

您在此行上使用的-LDAPFilter错误:

Get-ADuser -LDAPFilter "(samaccountname=$_)" -Server dc:3268
-LDAPFilter用于以LDAP语法编写过滤器。

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

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

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

关于variables - Get-ADuser:无法识别搜索过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27557783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com