[英]Active Directory Powershell - Get OU details
Below is the code: PowerShell 2.0 下面是代码: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
Upon execution I get the below error: 执行后,出现以下错误:
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
Can someone please help? 有人可以帮忙吗?
Try it this way: 尝试这种方式:
$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 will return a string rather than a PSObject so you don't need out-string. select-object -expandproperty将返回字符串而不是PSObject,因此您不需要字符串。
Bill 法案
$DomainDN = Get-ADDomain -Server $svr | Select -ExpandProperty DistinguishedName
要么
$DomainDN = (Get-ADDomain -Server $svr).DistinguishedName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.