Sample script that searches Active Directory for all the users that have the Exchange server o=fabrikam/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=atl-msg-01. The msExchHomeServerName attribute is replicated to the Global Catalog. This means you can connect to a Global Catalog server and search across the forest for users having a specified Exchange server. This attribute is available only if you have installed Microsoft Exchange.

PowerShell
Edit|Remove
$strFilter = "(&(objectCategory=User) `
    (msExchHomeServerName=/o=fabrikam/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=atl-msg-01))"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
    {$objItem = $objResult.Properties; $objItem.name}