3

以下はコードです: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

誰か助けてもらえますか?

4

2 に答える 2

2

この方法で試してください:

$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は必要ありません。

明細書

于 2013-03-07T15:35:54.490 に答える
0
$DomainDN = Get-ADDomain -Server $svr | Select -ExpandProperty DistinguishedName

また

$DomainDN = (Get-ADDomain -Server $svr).DistinguishedName
于 2013-03-07T15:31:12.160 に答える