$graphSPN = Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0000-c000-000000000000'"
$permission = "Application.ReadWrite.All"
$appRole = $graphSPN.AppRoles |
Where-Object Value -eq $permission |
Where-Object AllowedMemberTypes -contains "Application"
Verify:
$appRole
$sp = Get-MgServicePrincipal -ServicePrincipalId <ID of App>
$bodyParam = @{
PrincipalId = $sp.Id
ResourceId = $graphSPN.Id
AppRoleId = $appRole.Id
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -BodyParameter $bodyParam