|
1 | 1 | # This script grants the necessary Microsoft Graph API permissions to the Service Principal. |
2 | | -# Before running, change the $TenantID (line5) to your AAD Tenant ID and the $DisplayNameofMSI (line6) to the name of your Logic App |
3 | | -# This script requires the AzureAD Powershell Module, Install-Module AzureAD |
| 2 | +# Before running, change the $TenantID (line5) to your Entra ID Tenant ID and the $DisplayNameofMSI (line6) to the name of your Logic App |
| 3 | +# This script requires the Microsoft.Graph PowerShell Module: Install-Module Microsoft.Graph -Scope CurrentUser |
4 | 4 |
|
5 | | -$TenantID="" #AAD Tenant Id |
| 5 | +$TenantID="" #Entra ID Tenant Id |
6 | 6 | $DisplayNameOfMSI="Add-IP-Entity-To-Named-Location" # Name of the managed identity |
7 | 7 |
|
8 | | -Connect-AzureAD -TenantId $TenantID |
| 8 | +Connect-MgGraph -TenantId $TenantID -Scopes "Application.Read.All", "AppRoleAssignment.ReadWrite.All" |
9 | 9 |
|
10 | | -$MSI = (Get-AzureADServicePrincipal -Filter "displayName eq '$DisplayNameOfMSI'") |
| 10 | +$MSI = Get-MgServicePrincipal -Filter "displayName eq '$DisplayNameOfMSI'" |
11 | 11 |
|
12 | 12 | Start-Sleep -Seconds 5 |
13 | 13 |
|
14 | 14 | #Microsoft Graph API - Policy.Read.All |
15 | 15 | $GraphAppId = "00000003-0000-0000-c000-000000000000" |
16 | 16 | $PermissionName = "Policy.Read.All" |
17 | | -$GraphServicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq '$GraphAppId'" |
| 17 | +$GraphServicePrincipal = Get-MgServicePrincipal -Filter "appId eq '$GraphAppId'" |
18 | 18 | $AppRole = $GraphServicePrincipal.AppRoles | Where-Object {$_.Value -eq $PermissionName -and $_.AllowedMemberTypes -contains "Application"} |
19 | | -New-AzureAdServiceAppRoleAssignment -ObjectId $MSI.ObjectId -PrincipalId $MSI.ObjectId -ResourceId $GraphServicePrincipal.ObjectId -Id $AppRole.Id |
| 19 | +New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $MSI.Id -PrincipalId $MSI.Id -ResourceId $GraphServicePrincipal.Id -AppRoleId $AppRole.Id |
20 | 20 |
|
21 | 21 | Start-Sleep -Seconds 5 |
22 | 22 |
|
23 | 23 | #Microsoft Graph API - Policy.ReadWrite.ConditionalAccess |
24 | 24 | $GraphAppId = "00000003-0000-0000-c000-000000000000" |
25 | 25 | $PermissionName = "Policy.ReadWrite.ConditionalAccess" |
26 | | -$GraphServicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq '$GraphAppId'" |
| 26 | +$GraphServicePrincipal = Get-MgServicePrincipal -Filter "appId eq '$GraphAppId'" |
27 | 27 | $AppRole = $GraphServicePrincipal.AppRoles | Where-Object {$_.Value -eq $PermissionName -and $_.AllowedMemberTypes -contains "Application"} |
28 | | -New-AzureAdServiceAppRoleAssignment -ObjectId $MSI.ObjectId -PrincipalId $MSI.ObjectId -ResourceId $GraphServicePrincipal.ObjectId -Id $AppRole.Id |
| 28 | +New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $MSI.Id -PrincipalId $MSI.Id -ResourceId $GraphServicePrincipal.Id -AppRoleId $AppRole.Id |
29 | 29 |
|
30 | | -# Disconnect-AzureAD |
| 30 | +Disconnect-MgGraph |
0 commit comments