Skip to content

Instantly share code, notes, and snippets.

@ykfq
Forked from bill-long/SearchAllDCsForFilter.ps1
Created August 9, 2016 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykfq/2b19d9b44ccfed98925dc779b9266c20 to your computer and use it in GitHub Desktop.
Save ykfq/2b19d9b44ccfed98925dc779b9266c20 to your computer and use it in GitHub Desktop.
$filter = "(proxyAddresses=SMTP:foo@contoso.com)"
$gcs = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs
$gcs | % {
$searcher = $_.GetDirectorySearcher()
$searcher.Filter = $filter
$results = $searcher.FindAll()
if ($results.Count -gt 0)
{
$results
}
else
{
"Not found on GC: " + $_.Name
}
}
$domains = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Domains
$domains | % {
$dcs = $_.DomainControllers
$dcs | % {
$searcher = $_.GetDirectorySearcher()
$searcher.Filter = $filter
$results = $searcher.FindAll()
if ($results.Count -gt 0)
{
$results
}
else
{
"Not found on DC: " + $_.Name
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment