I'm trying to automate the activation of my PIM Entra ID role for Azure Tenant with either Azure CLI or PowerShell.
I've followed the answers in Activate PIM role for Azure resources via REST / Powershell? but I suspect the problem here is that my role is a tenant-wide, Entra Id role of Global Administrator
$UserId = az ad signed-in-user show --query id -o tsv
$GlobalAdminRoleId = "62e90394-69f5-4237-9190-012177145e10"
# JSON body
@{
principalId = $UserId
roleDefinitionId = $GlobalAdminRoleId
requestType = 'selfActivate'
justification = "Temporary Global Admin access for deployment purposes"
principalType = "User"
assignmentState = "Active"
directoryScopeId = "/"
scheduleInfo = @{
startDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
expiration = @{
type = "AfterDuration"
duration = "PT1H"
}
}
} | `
ConvertTo-Json -Compress | `
Set-Content -Path "$PSScriptRoot/roleAssignmentBody.json" -Encoding utf8 -Force
# Activate the role
az rest --method POST `
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments" `
--headers "Content-Type=application/json" `
--body "@$PSScriptRoot/roleAssignmentBody.json"
After running the script I always get Authorization_RequestDenied:
Forbidden({"error":{"code":"Authorization_RequestDenied","message":"Insufficient privileges to complete the operation.","innerError":{"date":"2025-10-30T13:34:44","request-id":"ced3a465-4dc8-4974-bc64-f81f3586db46","client-request-id":"ced3a465-4dc8-4974-bc64-f81f3586db46"}}})
But the role is available in Azure Portal and I've verified I can activate it there, so this error can't be due to missing privileges:
