【问题标题】:Check if AD group exists or not检查AD组是否存在
【发布时间】:2014-07-30 17:32:50
【问题描述】:

尝试使用以下脚本检查 AD 组是否存在:

$Path = "LDAP://dc=cmc,dc=com"
$object = "CMC\QTKS-DEP-Admin-Temp"
$type = "Group"

$search = [System.DirectoryServices.DirectorySearcher]$Path
$search.Filter = "(&(name=$object)(objectCategory=$type))"
$Result = $search.FindOne()

IF( $Result -eq $null)
{
Write-Host "Group does not exist"
}
Else 
{   
Write-Host "Group exists"
}

我知道 LDAP 连接字符串或变量声明有问题。或者是其他东西。有人可以纠正。即使存在,结果也总是显示为“组不存在”。

【问题讨论】:

    标签: ldap exists adgroup


    【解决方案1】:

    终于明白了:

    $Search = New-Object DirectoryServices.DirectorySearcher
    $Search.Filter = '(&(objectCategory=Group)(anr=CMC\QTKS-DEP-Admin-Temp))'
    $Search.SearchRoot = 'LDAP://DC=cmc,DC=com'
    $Result = $Searcher.FindOne()
    
    IF( $Result -eq $null)
    {
    Write-Host "Group does not exist"
    }
    Else 
    {              
    Write-Host "Group exists"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 2011-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多