Good afternoon
I have selected stackoverflow for this question because probably mainly programmers are confronted with this question:
This is the issue:
If we call Get-AzADUser
to get all AAD Users in the Azure Automation Runbook, then we get: Error 'Insufficient privileges'
We do it like this:
- We have an Automation Account with an "Azure Run As Account"
- In the PowerShell Runbook we call:
# Connect to AAD
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
$account = Connect-AzAccount -ServicePrincipal `
-TenantId $Conn.TenantID `
-ApplicationId $Conn.ApplicationID `
-CertificateThumbprint $Conn.CertificateThumbprint
# Get All AAD Users
$AllADUsers = Get-AzADUser
- If we start the Runbook, we get the Error:
> Get-AzADUser : Insufficient privileges to complete the operation.
> FullyQualifiedErrorId :
> Microsoft.Azure.Commands.ActiveDirectory.GetAzureADUserCommand
This is the permissions configuration:
- The
Automation Account
has setRun as accounts
»Azure Run As Account
(and not an Azure Classic Run As Account) - In fact,
Azure Run As Account
is misleading, it is a Registered App and can be found in AzureApp registrations
- The Registered App has these settings:
» A custom role with all permissions.
» API Permissions:
Microsoft Graph (6)
Delegated Directory.AccessAsUser.All
Delegated Directory.ReadWrite.All
Delegated User.ReadWrite.All
Application Directory.ReadWrite.All
Application User.Export.All
Application User.ReadWrite.All
» All API Permissions are Granted for our Tenant
Unfortunately, we still get the Error 'Insufficient privileges'
Thanks a lot for any help!
Kind regards, Thomas