Using PowerShell to generate report of all Azure AD users with Manager

Description:

This script is used to get all the Azure AD user's and their Managers

Script:

Install-Module -Name AzureAD

Connect-AzureAD

Install-Module -Name Msonline

Connect-MsolService

Install-Module -Name MicrosoftTeams

Connect-MicrosoftTeams

$output = @()

$users = Get-AzureADUser -All $true

foreach ($user in $users) {

    $manager = Get-AzureADUserManager -ObjectId $user.ObjectId

    $data = New-Object -TypeName psobject

    $data | Add-Member -MemberType NoteProperty -Name UsersObjectId -Value $user.ObjectId

    $data | Add-Member -MemberType NoteProperty -Name UserUPN -Value $user.UserPrincipalName

    $data | Add-Member -MemberType NoteProperty -Name UserType -Value $user.UserType

    $data | Add-Member -MemberType NoteProperty -Name ManagersObjectId -Value $manager.ObjectId

    $data | Add-Member -MemberType NoteProperty -Name ManagerUPN -Value $manager.UserPrincipalName

    $data | Add-Member -MemberType NoteProperty -Name ManagerUserType -Value $manager.UserType

    $output += $data

}

$output | Export-Csv -Path output.csv -NoTypeInformation

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us