Forum Discussion

Shashikant_Gagare's avatar
Shashikant_Gagare
Copper Contributor
Mar 08, 2023
Solved

Get-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is null.

Hi All, I am trying to fetch the Manager's Manager using the "Get-AzureADUserManager" function by passing ObjectId of manager. However while passing the manager's object to get his/her manager , ...
  • Varun_Ghildiyal's avatar
    Mar 08, 2023

    Shashikant_Gagare 

     

    It looks like you are trying to get the manager's manager by passing the ObjectId of the $manager object, but the $manager object itself is null. This is causing the Get-AzureADUserManager cmdlet to fail.

    To avoid this error, you should first check if the $manager object is not null before trying to get its manager. You can do this by adding a simple if statement:

     

     

    foreach($user in $users)
    {
        $row = $Datatable.NewRow()
    
        $manager=Get-AzureADUserManager -ObjectId $user.ObjectId
    
        if($manager -ne $null)
        {
            $seniorM=Get-AzureADUserManager -ObjectId $manager.ObjectId
            $row.seniorM=$seniorM.DisplayName
        }
    
        $row.Name=$user.GivenName
        $row.Surname=$user.Surname
        $row.manager=$manager.DisplayName
    
        $Datatable.Rows.Add($row)
    }

     

    This way, if the $manager object is null, the if statement will prevent the $seniorM object from being created and the script will continue without throwing an error.

Resources