Skip to Content
Communication Square LLC Help Center

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

Written October 2020. Microsoft changes these admin screens often, so the screenshots below may not match what you see today. The sequence of steps is usually still correct — if something looks wrong, tell us and we'll update it.

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

Last updated on