0

Hi I am wanting to get App registration information for several applications within my tenant (but different subscriptions) using an Automation Account Runbook. I currently have a System Assigned managed identity on the automation account. Inside my powreshell workflow runbook I have the following snippet of code:

try{
            "Logging in to Azure..."
            #Connect-AzAccount
            Connect-AzAccount -Identity
            $token = (Get-AzAccessToken -ResourceTypeName MSGraph).token
            $secreToken = ConvertTo-SecureString -String $token -AsPlainText -Force
            Connect-MgGraph -AccessToken $secreToken
            }
            catch{
                Write-Error -Message $_.Exception
                throw $_.Exception
                }


$apps = Get-AzADApplication

When I run the runbook I get an Insufficient privileges to complete the operation. error message. Is there anyway to run Get-AzADApplication using a managed identity in this way? If not, is there a better authentication method to use?

  • What kind of AAD roles your MSI has? – jikuja Jan 18 '23 at 17:49
  • If I go AAD->Enterprise Applications->Search my MSI->Role and administrators I see Application Credential Administrator, Cloud application Administrator, Reports Reader, and XOM - Application Role Administrator – new_programmer_22 Jan 18 '23 at 18:01

1 Answers1

1

Firstly, I have tried your code and got similar error as you got as below:

enter image description here

Now, Firstly go to azure active directory and then click on Roles and administrators:

enter image description here

Then search directory Readers as below and then click on it:

enter image description here

Then click on add Assignments as below:

enter image description here

Then select a member as below:

enter image description here

then click on next:

enter image description here

Now then I go back to runbook and when I run the error is resolved: enter image description here

RithwikBojja
  • 5,069
  • 2
  • 3
  • 7