Score:0

Powershell script to export information to a CSV file

cz flag

I am trying to figure out why Business Phone is not populating in the report. Any assistance with be greatly appreciated

    # Connect to AzureAD
Connect-AzureAD

# Get all Azure AD users
$AzADUsers = Get-AzureADUser -All $true

# Display progress bar
$progressCount = 0
for ($i = 0; $i -lt $AzADUsers.Count; $i++) {

    Write-Progress `
        -Id 0 `
        -Activity "Retrieving User " `
        -Status "$progressCount of $($AzADUsers.Count)" `
        -PercentComplete (($progressCount / $AzADUsers.Count) * 100)

    $progressCount++

}

# Create list
$AzADUsers | Sort-Object GivenName | Select-Object `
@{Label = "First name"; Expression = { $_.GivenName } },
@{Label = "Last name"; Expression = { $_.Surname } },
@{Label = "Display name"; Expression = { $_.DisplayName } },
@{Label = "User type"; Expression = { $_.UserType } },
@{Label = "E-mail"; Expression = { $_.Mail } },
@{Label = "Job Title"; Expression = { $_.JobTitle } },
@{Label = "Company"; Expression = { $_.CompanyName } },
@{Label = "Manager"; Expression = { (Get-AzureADUserManager -ObjectId $_.ObjectId).DisplayName } },
@{Label = "Office"; Expression = { $_.PhysicalDeliveryOfficeName } },
@{Label = "Employee ID"; Expression = { $_.ExtensionProperty.employeeId } },
@{Label = "Dirsync"; Expression = { if (($_.DirSyncEnabled -eq 'True') ) { 'True' } Else { 'False' } } },
@{Label = "Business Phone"; Expression = { if ($_.BusinessPhones) { $_.BusinessPhones[0] } else { "N/A"} } },
@{Label = "Mobile"; Expression = { $_.Mobile } },
@{Label = "Account status"; Expression = { if (($_.AccountEnabled -eq 'True') ) { 'Enabled' } Else { 'Disabled' } } } |

# Export report to CSV file
Export-Csv -Encoding UTF8 -Path "c:\scripts\Users.csv" -NoTypeInformation
cn flag
Looks like this attribute may be single valued. See: https://stackoverflow.com/questions/36914162/user-businessphones-property-multi-valued
Score:0
cz flag
@{Label = "Business Phone"; Expression = { $users = Get-MsolUser -All $users |Select-Object -ExpandProperty PhoneNumber} },

I found this to work

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.