How to add permissions to Azure AD apps with PowerShell

170 views Asked by At

I am registering an app to Azure AD using PowerShell(Microsoft Graph SDK). I would like to add API permissions to the registered Azure AD app. I want to add it to "Configured Permissions", but it gets added to "Other Permissions". I would appreciate it if you could tell me the cause and how to deal with it. thank you.

When I executed the command below, it completed successfully, but when I opened Azure Portal, it was registered in "Other permissions". I wanted to add it to the "Configured Permissions", and although I tried several things, it was not added to the "Configured Permissions".

$AppRole = $GraphServicePrincipal.AppRoles | Where-Object {$_.Value -eq "User.ReadWrite.All" -and $_.AllowedMemberTypes -contains "Application"}

$params = @{
        principalId = $servicePrincipal.Id #Service Principal ID
        resourceId = $GraphServicePrincipal.Id #Microsoft Graph Service Principal ID
        appRoleId = $AppRole.Id
    }
# command1
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $params.principalId -BodyParameter $params
# command2
New-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $servicePrincipal.Id -BodyParameter $params
1

There are 1 answers

2
Mohamed Azarudeen Z On

If you want to grant application permissions to your AD app and have them appear under "Configured Permissions" in the Azure Portal, you need to give yes to these permissions. as u asked see code in powershell below

This will generate consent URL

# Specify your Azure AD app's Application (client) ID
$appId = "your-app-id"

# Generate the consent URL
$consentUrl = Get-MgAppConsentUrl -AppId $appId -RedirectUri "https://yourredirecturi"

later

output the URL that is generated

Write-Host "Consent URL: $consentUrl"

After consenting this, check the Azure Portal under the "API permissions" section for your app. The app roles will appear under "Configured Permissions."