Grant API permissions
Here we will grant Graph API permissions to the managed identity of your automation account so it can access data from MS Graph.
Managed identity
# Tenant Id
$TenantId = "<MyTenantId>"
# List of permission names
$RolesToAssign = @(
"DeviceManagementApps.Read.All"
"DeviceManagementConfiguration.Read.All"
"DeviceManagementServiceConfig.Read.All"
"CloudPC.Read.All"
"DeviceManagementRBAC.Read.All"
"GroupMember.Read.All"
"DeviceManagementScripts.Read.All"
)
# DisplayName of the Enterprise App you are assigning permissions to
$EnterpriseAppName = "<MyAppName>"
# Connect to Graph
Import-Module Microsoft.Graph.Applications
Connect-Graph -TenantId $TenantId -NoWelcome
# Get the service principals
$GraphApp = Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0000-c000-000000000000'" # Microsoft Graph
$EnterpriseApp = Get-MgServicePrincipal -Filter "DisplayName eq '$EnterpriseAppName'"
# Assign the roles
foreach ($Role in $RolesToAssign) {
$Role = $GraphApp.AppRoles | Where-Object { $_.Value -eq $Role }
$params = @{
principalId = $EnterpriseApp.Id
resourceId = $GraphApp.Id
appRoleId = $Role.Id
}
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $EnterpriseApp.Id -BodyParameter $params
}
PreviousCreate / configure an Azure automation accountNextCreate / configure an Azure storage account
Last updated
Was this helpful?