Active Directory Powershell - 获取OU详细信息

时间:2013-03-07 15:20:52

标签: powershell

以下是代码:PowerShell 2.0

$DomainDN = Get-ADDomain -Server $svr | Select DistinguishedName | Out-String
$CountryDN = Get-ADOrganizationalUnit -Server $svr -LDAPFilter '(name=Countries)' -SearchBase '$DomainDN' -SearchScope 0 | Select DistinguishedName | Out-String

执行后,我收到以下错误:

Get-ADOrganizationalUnit : The supplied distinguishedName must belong to one of the following partition(s): 'CN=Configuration,DC=lab,DC=mydomain,DC=com , CN=Sche
ma,CN=Configuration,DC=lab,DC=mydomain,DC=com , DC=eul,DC=lab,DC=mydomain,DC=com , DC=ForestDnsZones,DC=lab,DC=mydomain,DC=com , DC=DomainDns
Zones,DC=eul,DC=lab,DC=mydomain,DC=com'.
At line:3 char:38
+ $CountryDN = Get-ADOrganizationalUnit <<<<  -Server $svr -LDAPFilter '(name=Countries)' -SearchBase '$DomainDN' -SearchScope 0 | Select DistinguishedName | Out-String
    + CategoryInfo          : InvalidArgument: (:) [Get-ADOrganizationalUnit], ArgumentException
    + FullyQualifiedErrorId : The supplied distinguishedName must belong to one of the following partition(s): 'CN=Configuration,DC=lab,DC=mydomain,DC=com , CN= 
   Schema,CN=Configuration,DC=lab,DC=mydomain,DC=com , DC=eul,DC=lab,DC=mydomain,DC=com , DC=ForestDnsZones,DC=lab,DC=mydomain,DC=com ,
   DC=DomainDnsZones,DC=eul,DC=lab,DC=mydomain,DC=com'.,Microsoft.ActiveDirectory.Management.Commands.GetADOrganizationalUnit

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

以这种方式尝试:

$domainDN = get-addomain -server $svr | 
  select-object -expandproperty DistinguishedName
$countryDN = get-adorganizationalunit -server $svr -ldapfilter '(name=Countries)' `
  -searchbase $domainDN | select-object -expandproperty DistinguishedName

select-object -expandproperty将返回一个字符串而不是PSObject,因此您不需要out-string。

比尔

答案 1 :(得分:0)

$DomainDN = Get-ADDomain -Server $svr | Select -ExpandProperty DistinguishedName

$DomainDN = (Get-ADDomain -Server $svr).DistinguishedName
相关问题