Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created July 18, 2016 17:57
Show Gist options
  • Save bill-long/e146e34746c8bd880a9580846f5d9330 to your computer and use it in GitHub Desktop.
Save bill-long/e146e34746c8bd880a9580846f5d9330 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