【发布时间】:2018-09-10 20:53:59
【问题描述】:
我有一个文本文件 test.txt,其中包含一个 OU 列表,我需要在其中计算在每个 OU 中找到的用户数量。
test.txt:
我将其传递给 PowerShell 中的命令:
Get-Content .\test.txt | Out-String | ForEach-Object {
(Get-ADUser -Filter * -SearchBase "$_").Count
}
我收到以下错误:
Get-ADUser :提供的 distinctName 必须属于 以下分区:'DC=Mydomain,DC=net, CN=配置,DC=Mydomain,DC=net, CN=Schema,CN=Configuration,DC=Mydomain,DC=net, DC=ForestDnsZones,DC=Mydomain,DC=net, DC=DomainDnsZones,DC=Mydomain,DC=net'。 在行:1 字符:62 + ... ing) | ForEach-Object {(Get-ADUser -Filter * -SearchBase "$_").Count} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser但是,当我单独运行 OU 时,它可以工作。
PS> (Get-ADUser -Filter * -SearchBase "ou=MyOU1,dc=Mydomain,dc=net").Count
10782
【问题讨论】:
标签: powershell active-directory powershell-5.0