MgGraph PowerShell

SenhorDolas 1,271 Reputation points
2024-07-03T15:36:10.0166667+00:00

Hi Everyone,

I need to clear the User Consent permissions on an Enterprise App so I can run the 3rd party app again and then grant "Consent on behalf of your organisation" so all users (assigned to the Ent App) can access it.
User's image

Using MgGraph PowerShell to remove permissions from an Enterprise App and I get this pop up:

Connect-MgGraph -Scopes "Application.ReadWrite.All", "DelegatedPermissionGrant.ReadWrite.All"
# Get Service Principal using objectId
$sp = Get-MgServicePrincipal -ServicePrincipalId xxxxxx
# Get MS Graph App role assignments using objectId of the Service Principal
$assignments = Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $sp.Id -All
# Remove all users and groups assigned to the application
$assignments | ForEach-Object {
    if ($_.PrincipalType -eq "User") {
        Remove-MgUserAppRoleAssignment -UserId $_.PrincipalId -AppRoleAssignmentId $_.Id
    } elseif ($_.PrincipalType -eq "Group") {
        Remove-MgGroupAppRoleAssignment -GroupId $_.PrincipalId -AppRoleAssignmentId $_.Id
    }
}

User's image

What is this for and should I accept and grant "Consent on behalf of your organisation".

Thanks, M

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,252 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,272 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 99,351 Reputation points MVP
    2024-07-03T16:52:56.01+00:00

    Those permissions are required in order for the PowerShell's Remove-MgUserAppRoleAssignment cmdlet to work. Without them, the script above will fail.

    If you don't want to grant such permissions (and generally speaking you should not be keeping such around, as they are quite sensitive), you can instead just delete the service principal object itself via the Entra admin portal. Select the SP > go to Properties > hit Delete. Then you can just re-consent to the app.

    0 comments No comments