ykfq
8/9/2016 - 8:19 AM

Check every GC and DC for a specific objectGUID

Check every GC and DC for a specific objectGUID

$guid = "bc87047d-25e8-11d3-9079-00805f31f826"

$gcs = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs
$gcs | % {
    $entry = [ADSI]("GC://" + $_.Name + "/<GUID=" + $guid + ">")
    if ($entry.Guid -ne $null)
    {
        $entry
    } 
    else 
    {
        "Not found on GC: " + $_.Name
    }
}

$domains = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains
$domains | % {
    $dcs = $_.DomainControllers
    $dcs | % {
        $entry = [ADSI]("LDAP://" + $_.Name + "/<GUID=" + $guid + ">")
        if ($entry.Guid -ne $null)
        {
            $entry
        } 
        else 
        {
            "Not found on DC: " + $_.Name
        }
    }
}