Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nathanmcnulty/c353279b9704140a1a8a11c26932f969 to your computer and use it in GitHub Desktop.
Save nathanmcnulty/c353279b9704140a1a8a11c26932f969 to your computer and use it in GitHub Desktop.
Set up Maester permissions
# 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