使用“0”参数调用“FindAll”的异常 - 可信域LDAP搜索

时间:2017-07-17 08:26:27

标签: powershell attributes ldap trusted

我的方法是在扫描所有DC后获取最新的ModifyTimeStamp。我的代码中的场景是:

首先,我在PDC上扫描以获取distinguishedName值,然后我扫描所有DC也获得distinguishedName值,如果它们彼此-eq,它会打印ModifyTimeStamp,这意味着每个DC上的所有ModifyTimeStamp值都将存储在一个arraylist中。 arraylist将打印最大值。如下:

$TrustedDomain = "test.com"
$context = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext("domain",$TrustedDomain)
$D = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($context)
$PDC = $D.PdcRoleOwner 
$ADSearch = New-Object System.DirectoryServices.DirectorySearcher 
$ADSearch.SearchRoot ="LDAP://$PDC"
$ADSearch.SearchScope = "subtree"
$ADSearch.PageSize = 100
$ADSearch.Filter = "(&(objectCategory=person)(objectClass=user))"
foreach($pro in $properies)
{
    $ADSearch.PropertiesToLoad.add($pro)| out-null
}
$userObjects = $ADSearch.FindAll()

$dnarr = New-Object System.Collections.ArrayList
Function modiScan{
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher 
    $Searcher.PageSize = 100 
    $Searcher.SearchScope = "subtree" 
    $Searcher.Filter = "(&(objectCategory=person)(objectClass=user))"
    $Searcher.PropertiesToLoad.Add("distinguishedName")|Out-Null
    $Searcher.PropertiesToLoad.Add("modifyTimeStamp")|Out-Null
    forEach ($users In $userObjects) 
    { 

            $DN = $users.Properties.Item("distinguishedName")[0]
            $dnarr.add($DN)|Out-Null
    }
    #$dnarr
    foreach($dnn in $dnarr){
                $lastmd = New-Object System.Collections.ArrayList
                ForEach ($DC In $D.DomainControllers){

                    $Server = $DC.Name
                    $Base = "LDAP://$Server/"+$dnn
                    $Searcher.SearchRoot = $Base 
                    $Results2 = $Searcher.FindAll()
                    ForEach ($Result2 In $Results2) 
                    {                          
                        $DN2 = $Result2.Properties.Item("distinguishedName")[0]
                        if($DN2 -eq $dnn){
                            $modi = $Result2.Properties.Item("modifyTimeStamp")[0]
                            $lastmd.Add($modi)|Out-Null
                        } 
                    } 
                }
      $lastModi = ($lastmd |measure -max).maximum      
      if($lastModi -ne $null){   
            $lastModi = $lastModi.ToString("yyyy/MM/dd")               
        }
        else{
            $lastModi = "N/A"
        }


        $lastModi
   }
}
modiScan

我得到的错误是:

Exception calling "FindAll" with "0" argument(s): "Unknown error (0x80005000)"
At C:\Users\Ender\trustedScan.ps1:40 char:21
+                     $Results2 = $Searcher.FindAll()
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : COMException

我已经在当前的域上执行了它的工作就像一个魅力。但是,当我尝试放置一个受信任的域时,它会把这个错误抛给我。

0 个答案:

没有答案