Share via

Powershell Graph set user Manager through an App using Set-MgUserManagerByRef

Paul van der Elst 20 Reputation points
2025-05-23T10:28:35.39+00:00

I'm using an App with consented delegated permissions Directory.ReadWrite.All and User.ReadWrite.All. I'm using Set-MgUserManagerByRef to set the Manager property of an account like:


$body = @{
    grant_type    = "client_credentials"
    scope         = $scope
    client_id     = $clientId
    client_secret = $clientSecret
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -ContentType "application/x-www-form-urlencoded" -Body $body
    $accessToken = $tokenResponse.access_token

$newManagerRef = @{
    "@odata.id" = "https://graph.microsoft.com/v1.0/users/" + $manager.Id
}

# Update the manager property
Set-MgUserManagerByRef -UserId $adminuser.Id -BodyParameter $newManagerRef

Set-MgUserManagerByRef returns this error: Insufficient privileges to complete the operation. Status: 403 (Forbidden) ErrorCode: Authorization_RequestDenied.

What (permission) am I missing?

Regards, Paul

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments

Answer accepted by question author

Andy David - MVP 160.2K Reputation points MVP Volunteer Moderator
2025-05-23T11:09:49.6+00:00

If you are using an app to update, then you need to use application level perms, not delegated perms

User's image

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.