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