我有这个cmdlet,我想只限于一个OU的结果:
Get-ADUser -Filter {(Enabled -eq $false)} | ? { ($_.distinguishedname -notlike '*Disabled Users*') }
现在我试图使用
-searchbase "ou=FirstOU,dc=domain,dc=com"
但是,如果我使用-SearchBase我得到这个错误:
Where-Object : A parameter cannot be found that matches parameter name 'searchb ase'. At line:1 char:114 + Get-ADUser -Filter {(Enabled -eq $false)} | ? { ($_.distinguishedname -notli ke '*Disabled Users*') } -searchbase <<<< "ou=FirstOU,dc=domain,dc=com" + CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBi ndingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm ands.WhereObjectCommand
我试图做的是从一个特定的OU获得所有的禁用用户,但是,有一个OU内部,我要排除的FirstOU:“禁用用户”OU。
因为您可能已经猜到了我想要查找特定OU中不在该OU中的“Disabled Users”OU中的禁用用户。
我的结构:
Forest FirstOU Users,groups,etc... Disabled Users OU
-SearchBase参数必须与Get-ADUser一起使用,而不是Where-Object(别名?)。 这应该工作:
Get-ADUser -Filter {(Enabled -eq $false)} -SearchBase "ou=FirstOU,dc=domain,dc=com" | ? { ($_.distinguishedname -notlike '*Disabled Users*') }
将search限制到一个OU的最简单方法是使用SearchScope:
Get-ADUser -Filter {(Enabled -eq $false)} -SearchScope OneLevel -SearchBase "ou=FirstOU,dc=domain,dc=com"
最简单的方法是将-SearchBase放在-SearchBase之前。
Get-ADUser -searchbase "ou=FirstOU,dc=domain,dc=com" -Filter {(Enabled -eq $false)} | ? { ($_.distinguishedname -notlike '*Disabled Users*') }
通过在已经将-SearchBase传递给Get-ADUser后运行Where-Object ,可以解决必须使用-SearchBase和Get-ADUser ,而不是Where-Object ( ?是PowerShell中的Where-Object别名) 。