Created
August 7, 2024 07:34
-
-
Save nathanmcnulty/c353279b9704140a1a8a11c26932f969 to your computer and use it in GitHub Desktop.
Set up Maester permissions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list of permissions | |
[array]$permissions = "Directory.Read.All","Policy.Read.All","Reports.Read.All","DirectoryRecommendations.Read.All","PrivilegedAccess.Read.AzureAD","IdentityRiskEvent.Read.All","RoleEligibilitySchedule.Read.Directory","RoleManagement.Read.All","Policy.Read.ConditionalAccess","UserAuthenticationMethod.Read.All" | |
# create application | |
$app = New-MgApplication -DisplayName "Maester DevOps" | |
# create service principal | |
$graphSpId = (Get-MgServicePrincipal -Filter "displayName eq 'Microsoft Graph'").Id | |
$sp = New-MgServicePrincipal -AppId $app.appId | |
# grant permissions | |
$permissions | ForEach-Object { | |
$permission = $_ | |
$appRoleId = ((Get-MgServicePrincipal -Filter "displayName eq 'Microsoft Graph'" -Property AppRoles).appRoles | Where-Object { $_.Value -eq "$permission" }).Id | |
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -PrincipalId $sp.Id -AppRoleId $appRoleId -ResourceId $graphSpId | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment