【问题标题】:Checking for existence of OU检查OU是否存在
【发布时间】:2017-10-23 19:30:38
【问题描述】:

如何在不使用[adsi]::Exists() 方法的情况下检查组织单位的存在?我一辈子都无法让它在我的系统上运行。

【问题讨论】:

  • 你试过Get-ADOrganizationUnit吗?
  • 我已经尝试过并与之斗争。该文档告诉我很少使用。写得太技术性了,假设你已经理解了。
  • This article 给出了很好的使用示例。 If (Get-ADOrganizationalUnit -Identity 'OU=Europe,CN=Users,DC=corp,DC=contoso,DC=com') {'It exists!'}
  • “CN=Users”是什么意思?

标签: powershell active-directory ou


【解决方案1】:

Exists() 方法需要 LDAP URI 作为其参数:

$ou = 'ou=foo,dc=example,dc=com'
[adsi]::Exists("LDAP://$ou")

如果您想改用Get-ADOrganizationalUnit cmdlet:请使用-Filter 参数而不是-Identity 参数。前者通常对 AD cmdlet 更宽容:

$ou = 'ou=foo,dc=example,dc=com'
Get-ADOrganizationalUnit -Filter "distinguishedName -eq '$ou'"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 2018-09-10
    相关资源
    最近更新 更多