SOLVED

PowerShell command to export user's manager name

Copper Contributor

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

13 Replies

Hi @Gianni88 ,

in which context are you working? SharePoint online? Azure Active Directory?

Hi Federico,

Thank you for your reply.

I do have an Active Directory on permise synchronized to Azure. I hope it can helps you.

Gianni

Hi @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

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

@Federico Porceddu 

 

I tried to connect to Azure Active Directory PowerShell for Graph. but I am not able to get in. Maybe is because we use in our company MFA security.

 

Are there any others commands ?

 

Thanks.

 

Gianni

Hi @Gianni88 

what do you mean with "but I am not able to get in" ?

Any errors?

Cheers,

Federico 

Hi Federico,

 

As we use MFA (Multa Factor Authentification), I am not able to get into Powershell. I tried to follow this link (without success) : https://docs.microsoft.com/en-us/powershell/exchange/office-365-scc/connect-to-scc-powershell/mfa-co... 

 

Do you know which command I need to run to connect to Powershell Azure (with MFA) ? 

 

Thanks.

 

Gianni

Hi @Gianni88 ,

ok it's easy :)

 

You need to use just

Connect-AzureAD

instead of

$AzureAdCred = Get-Credential
Connect-AzureAD -Credential $AzureAdCred

 

the second part of the script it's the same :)

Cheers,

Federico

Hi Federico,

 

Thanks, step by step we move forward, I am in now :) 

 

When I run the ps1 file, it does not display anything (look at the attachment). 

 

What I am doing wrong ? 

 

Thanks.result1.jpg

Hi @Gianni88 ,

try to run 

> $users = Get-AzureADUser -All $true
> $users

after connect :)
Are there users in $users?

 

Cheers,

Federico

@Federico Porceddu 

 

Thanks, Better and better now. However, I do not have the Manager name (see below) :

It is possible to extract into a csv file ? 

 

Thanks.

 

Gianni

 

result2.jpg

best response confirmed by Gianni88 (Copper Contributor)
Solution

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

@Federico Porceddu 

 

Thanks Federico for your help !

@Federico Porceddu :

 

Found this powershell command also, it can help : 

 

Get-ADUser -Filter * -SearchBase 'OU=xxxx,OU=xxxxxx,DC=xxx' -Properties Manager, Title |
Select-Object -Property Name, Title, @{label='Manager';expression={$_.manager -replace '^CN=|,.*$'}}

 

It works perfectly

1 best response

Accepted Solutions
best response confirmed by Gianni88 (Copper Contributor)
Solution

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

View solution in original post