Skip to content

Instantly share code, notes, and snippets.

$searcher = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().FindGlobalCatalog()
$searcher.Filter = "(&(objectClass=user)(msExchMailboxMoveFlags=10))"
$results = $searcher.FindAll()
"Found " + $results.Count.ToString() + " results:"
foreach ($result in $results)
{
$dn = $result.Properties["distinguishedName"][0].ToString()
$dn
$entry = [ADSI]("LDAP://" + $dn)
$entry.Properties["msExchMailboxMoveFlags"].Clear()
$filter = "(proxyAddresses=SMTP:[email protected])"
$gcs = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs
$gcs | % {
$searcher = $_.GetDirectorySearcher()
$searcher.Filter = $filter
$results = $searcher.FindAll()
if ($results.Count -gt 0)
{
$results