Managed Identites
System assigned managed identity
User assigned managed identity
Assigning API permissions
$DestinationTenantId = "YOUR-TENANT-ID"
$MsiName = "THE-NAME-OF-THE-IDENTITY" # Name of system-assigned or user-assigned managed service identity. (System-assigned use same name as resource).
# Connect to Azure Account
Connect-AzAccount
# Connect to MS Graph with specific scope
Connect-MgGraph -TenantId $DestinationTenantId -Scopes AppRoleAssignment.ReadWrite.All, Directory.Read.All, Application.Read.All
# Roller för Appen WindowsDefenderATP
$oPermissions = @(
"Machine.Isolate"
"Alert.ReadWrite.All"
)
$GraphAppId = "fc780465-2017-40d4-a0c5-307022471b92" # AppId of WDATP, DO NOT CHANGE
$oMsi = Get-AzADServicePrincipal -Filter "displayName eq '$MsiName'"
$oGraphSpn = Get-AzADServicePrincipal -Filter "appId eq '$GraphAppId'"
$oAppRole = $oGraphSpn.AppRole | Where-Object {($_.Value -in $oPermissions) -and ($_.AllowedMemberType -contains "Application")}
foreach($AppRole in $oAppRole)
{
$oAppRoleAssignment = @{
"PrincipalId" = $oMSI.Id
"ResourceId" = $oGraphSpn.Id
"AppRoleId" = $AppRole.Id
}
New-MgServicePrincipalAppRoleAssignment `
-ServicePrincipalId $oAppRoleAssignment.PrincipalId `
-BodyParameter $oAppRoleAssignment `
-Verbose
}
$GraphAppId = "00000003-0000-0000-c000-000000000000" # Appid of MS Graph, DO NOT CHANGE
$oPermissions = @(
"SecurityAlert.ReadWrite.All"
)
$oGraphSpn = Get-AzADServicePrincipal -Filter "appId eq '$GraphAppId'"
$oAppRole = $oGraphSpn.AppRole | Where-Object {($_.Value -in $oPermissions) -and ($_.AllowedMemberType -contains "Application")}
foreach($AppRole in $oAppRole)
{
$oAppRoleAssignment = @{
"PrincipalId" = $oMSI.Id
"ResourceId" = $oGraphSpn.Id
"AppRoleId" = $AppRole.Id
}
New-MgServicePrincipalAppRoleAssignment `
-ServicePrincipalId $oAppRoleAssignment.PrincipalId `
-BodyParameter $oAppRoleAssignment `
-Verbose
}Last updated