2013-03-07 74 views
1

下面是代碼:PowerShell 2.0中Active Directory的PowerShell的 - 獲取OU細節

$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 

是否有人可以幫忙嗎?

回答

1

試試這樣說:

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

選擇對象-ExpandProperty將返回一個字符串,而不是PSObject所以你不需要出去串。

Bill

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

$DomainDN = (Get-ADDomain -Server $svr).DistinguishedName 
相關問題