Forum Discussion
PowerShell command to export user's manager name
Dear all,
I would like to know what is the powershell command to get this information :
First Name | Last Name | Email address | JobTitle | Manager report Name |
|
|
|
|
|
It is one week that I am struggling with this command and I do not succeed.
Thank you in advance for your advice.
Regards.
Gianni
Hi Gianni88
it is normal you can't find the Manager field.
The foreach make the work for you, expanding manager property 🙂
Please, debug your scripts in ISE or using output messages 🙂
Cheers,Federico
Hi Gianni88 ,
in which context are you working? SharePoint online? Azure Active Directory?
- Gianni88Copper ContributorHi Federico,
Thank you for your reply.
I do have an Active Directory on permise synchronized to Azure. I hope it can helps you.
GianniHi Gianni88
you can try using Azure Active Directory PowerShell for Graph.
- first of all, install it following this guide ( Install-Module AzureAD )
- Connect to Azure AD using
$AzureAdCred = Get-Credential Connect-AzureAD -Credential $AzureAdCred
- Then you can use Get-AzureADUser command. ù
The result could be something like this
Connect-AzureAD -Credential $AzureAdCred $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 Name -Value $user.GivenName $data | Add-Member -MemberType NoteProperty -Name Surname -Value $user.Surname $data | Add-Member -MemberType NoteProperty -Name Mail -Value $user.Mail $data | Add-Member -MemberType NoteProperty -Name JobTitle -Value $user.JobTitle $data | Add-Member -MemberType NoteProperty -Name Manager -Value $manager.DisplayName $output += $data } $output | Format-Table
Save it in a .ps1 file and try it 🙂
I just follow this approach.
Cheers,
Federico