简体   繁体   English

Active Directory Powershell-获取OU详细信息

[英]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.

相关问题 Powershell在Active Directory中登录用户OU - Powershell get Logged on Users OU in Active Directory 如何在 Active Directory OU 中获取丢失的计算机名 - How to get missing Computernames in a Active Directory OU 如何使用Powershell从Active Directory中的特定OU获取没有ManageBy的组列表 - How to get list of groups with no ManageBy from a specific OU in Active Directory with Powershell Powershell Active Directory-将我的获取用户搜索限制为特定的OU [和子OU] - Powershell Active Directory - Limiting my get-aduser search to a specific OU [and sub OUs] 通过PowerShell代码将Active Directory OU导入SCCM - Importing Active Directory OU's to SCCM with thru PowerShell Code Powershell GUI - 是否有用于选择 OU 的 Active Directory 对话框? 像 FileOpenDialog 一样? - Powershell GUIs - Is there an Active Directory dialog box for selecting an OU? Like the FileOpenDialog? 在Powershell中循环浏览多个Active Directory Ou - Loop through multiple Active Directory Ou's in Powershell 使用Powershell将Active Directory组移动到另一个OU - Move Active Directory Group to Another OU using Powershell 使用PowerShell在内置OU中查找相邻OU中的Active Directory用户对象 - Finding Active Directory user objects in adjacent OU's to built in Users OU using PowerShell 尝试在 Ansible 中使用 Powershell 检索 OU 时未显示 Active Directory OU - Active Directory OU not being shown when trying to retrieve the OU using Powershell in Ansible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM