My ExportAzureADUserList not exporting correctly.

Helmut Lipp 20 Reputation points
2023-07-06T17:21:38.5633333+00:00

This particular line does not work. It pulls nothing .... I can validate the contents via the Bulk download procedure.

"Alt Email" = $azuser.alternateEmailAddress

This procedure is documented at

https://learn.microsoft.com/en-us/azure/active-directory/enterprise-users/users-bulk-download

Anyone have any ideas?

#Connect to Azure AD
#For more info - https://learn.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0#installing-the-azure-ad-module

#Install-Module AzureAD
Connect-AzureAD


#Path sets the Output location of the CSV file.
$path = "C:\TEMP\ADUsers-$(Get-Date -format "MM-dd-yyyy").csv"


#For Each will get all Enabled Azure AD Users and the following properties:
#Employee ID, First Name, Last Name, Work Email, Job Title, Department, Management Email, License
& {
    foreach($azuser in Get-AzureADUser -All $true -Filter 'accountEnabled eq true') {
        [pscustomobject]@{
            "First Name"    = $azuser.givenName
            "Last Name"     = $azuser.surname
            "Full Name"     = $azuser.displayName
            "Work Email"    = $azuser.UserPrincipalName
            "User Type"     = $azuser.usertype
            "Job Title"     = $azuser.JobTitle
            "Department"    = $azuser.department
            "Office Location"  = $azuser.physicalDeliveryOfficeName
            "Street Address" = $azuser.streetAddress
            "City"          = $azuser.city
            "State"         = $azuser.state
            "Postal Code"    = $azuser.postalCode
            "Telephone Number" = $azuser.telephoneNumber
            "Mobile Phone"   = $azuser.mobile
            "Alt Email" = $azuser.alternateEmailAddress
            "Auth Email"     = $azuser.authenticationEmail
            "Auth Alt Phone Number" = $azuser.authenticationAlternativePhoneNumbeAzureADUserlistr
            "Manager Name"  = (Get-AzureADUserManager -ObjectId $azuser.ObjectId).displayName
            
               }
    }
} | Export-CSV -Path $path -NoTypeInformation
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

Answer accepted by question author
  1. JamesTran-MSFT 37,226 Reputation points Microsoft Employee Moderator
    2023-07-11T20:50:29.02+00:00

    @Helmut Lipp

    Thank you for your post and I apologize for the delayed response!

    I understand that you're having issues retrieving the alternateEmailAddress data when it comes to downloading Azure AD users using your PowerShell script. To hopefully help point you in the right direction or resolve your issue, I'll share my findings below.


    Findings:

    When it comes to the $azuser.alternateEmailAddress parameter within your script, I reproduced your issue and was able to resolve it by using "Alt Email" = $azuser.OtherMails -join ";"

    User's image

    & {
        foreach($azuser in Get-AzureADUser -All $true -Filter 'accountEnabled eq true') {
            [pscustomobject]@{
                "First Name"    = $azuser.givenName
                "Last Name"     = $azuser.surname
                "Full Name"     = $azuser.displayName
                "Work Email"    = $azuser.UserPrincipalName
                "User Type"     = $azuser.usertype
                "Job Title"     = $azuser.JobTitle
                "Department"    = $azuser.department
                "Office Location"  = $azuser.physicalDeliveryOfficeName
                "Street Address" = $azuser.streetAddress
                "City"          = $azuser.city
                "State"         = $azuser.state
                "Postal Code"    = $azuser.postalCode
                "Telephone Number" = $azuser.telephoneNumber
                "Mobile Phone"   = $azuser.mobile
                "Other Emails Test" = $azuser.OtherMails -join ";"
                "Auth Email"     = $azuser.authenticationEmail
                "Auth Alt Phone Number" = $azuser.authenticationAlternativePhoneNumbeAzureADUserlistr
                "Manager Name"  = (Get-AzureADUserManager -ObjectId $azuser.ObjectId).displayName
                
                   }
        }
    } | Export-CSV -Path $path -NoTypeInformation
    

    I hope this helps!

    If you have any other questions, please let me know. Thank you for your time and patience throughout this issue.


    If the information helped address your question, please Accept the answer. This will help us and also improve searchability for others in the community who might be researching similar information.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.