Export list of users with specific domain in proxy addresses

Below is a powershell script you can use to find users in Active Directory with a specific mail domain and export the specific domain to csv.

Edit both @domain.com with the specific domain you are searching for within the users active directory proxyaddresses attribute

$users = get-aduser -filter * -Properties Name,UserPrincipalName,ProxyAddresses| ? {$_.ProxyAddresses -like "*@domain.com"}
[email protected]()
foreach ($user in $users) {
    $userobject= new-object PSObject # Create Array Row
    $userObject | Add-Member -MemberType NoteProperty -name "Name" -Value $($user.Name)
    $userObject | Add-Member -MemberType NoteProperty -name "UPN" -Value $($user.UserPrincipalName)
    foreach ($pa in ($($user.ProxyAddresses))) {
        if ($pa -like "*@domain.com") {
            $userObject | Add-Member -MemberType NoteProperty -name "Address$i" -Value $pa            
    $csvarray += $userobject                    
$csvarray | Export-CSV c:\temp\specificproxyaddressexport.csv  -notypeinformation

Ryan Wilson
Azure and Office 365 Technical Architect | Microsoft Certified Solutions Associate: Office 365 | Microsoft Certified: Azure Solutions Architect Expert | Microsoft Certified Solutions Expert: Productivity | Microsoft 365 Certified: Enterprise Administrator Expert | Microsoft 365 Certified: Messaging Administrator Associate

Leave a Reply

Your email address will not be published. Required fields are marked *