Hi @Deepaklal-FT ,
Thank you for posting query in Microsoft Q&A Platform.
Please note, when we create azure automation resource behind scenes it creates a service principle with which it actually runs the scripts. Lets say as part of our script execution we written PowerShell code to pause a Azure VM called
demoVM1
. In this case the service principle of Azure automation resource should have proper roles ondemoVM1
to perform that action. For example, If we grantcontributor
role to that service principle then when you run script it will perform the action and pause thedemoVM1
successfully.
Now, coming to your script, I could see at line 24, you are making an API call to some API URL. So here if that API has some mechanism to authenticate and authorize then we need to make sure to follow that.
Also, in line 25, I could see you are trying to make API call to storage account
. So here we need to make sure Azure automation account service principle should has proper role lets say contributor
role on storage account.
From error message, it seems currently error is happening at line 24, that means access related issues with API call to some URL. Kindly check with admins of that APIs and get details on how actually to authenticate and authorize with that API and make API call successful.
How to check the service principle of Azure Automation resource?
Inside Azure automation resource, go to connections and Click on "AzureRunAsConnection".
Go to Azure active directory, Click on App registrations and search with App id here.
Please note, usually this service principle display name will start with Azure automation resource name and then have some guid in it.
Hope this helps. Please let us know if any further queries.
------------
Please consider hitting Accept Answer
button. Accepted answers help community as well.