$mbx = get-mailbox -ResultSize unlimited $hash = @{} $mbx | % { $addresses = $_.EmailAddresses | ? {($_ -like "*smtp*")} foreach($address in $addresses) { $pos = $address.IndexOf("@") $suffix = $address.Substring($pos+1) if($suffix) { $hash[$suffix]++ } else { $hash["Blank"]++ } } } $hash.GetEnumerator() | Sort -Property Value -Descending | Out-File "SMTPDomains.txt"