Using Managed Identity in Azure Automation Runbook to connect to SharePoint Online #2559
Replies: 1 comment 1 reply
-
I am experiencing something similar using Azure Runbooks with managed identity - 401 unauthorized when attempting any commands although there were no errors with the connection. I have slightly different permissions - basically using sites.selected and then assigning the permissions for the site via Grant-PnPAzureADAppSitePermission as I don't want the managed identity to have full site access to all of SharePoint - the only issue we have found to date with sites.selected is the inability to create a new library in the site. This needs full sites permissions. I have two simple runbooks one using powershell 5.1 - this fails with 401 unauthorized. The only issue is that I need mggraph and that doesn't work with a managed account using an access token in 7.1 (json dependency error) but does work in 5.1. I'm not sure if Connect-PNPOnline -managedidentity is supposed to work in 5.1 but a simple test between 5.1 and 7.1 shows it doesn't in my case. I would redo your test with powershell 7.1 and see if it works. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks,
I am trying to connect to SharePoint Online from within an Azure Automation Runbook using a system assigned managed identity.
I noticed that 6 days ago a new release of pnp has been published, which includes the remark "Added system assigned Managed Identity support for SharePoint Online cmdlets. #2354"
Well I have been trying to use this feature for a couple of days now, but somehow I am not able to make it work.
I have enabled the system assigned identity on the 'Identity' tab of the Automation Account. Next, I have assigned permissions to the Enterprise application which had been created automatically by enabling the managed identity. Currently I have assigned the following permissions:
Eventually I want to limit it down to the least permissive permission level.
So what I want to achieve is that I can connect to any random SharePoint site collection and perform the Rename-PnPTenantSite cmdlet.
When I try the script below (just for testing purposes), I get the error: Unable to connect to the SharePoint Online Admin Center at 'https://orgname-admin.sharepoint.com' to run this cmdlet. Please ensure you pass in the correct Admin Center URL using Connect-PnPOnline -TenantAdminUrl and you have access to it. Error message: The remote server returned an error: (401) Unauthorized..
When I try the script below (just for testing purposes), I get the error: Suspended
The runbook job was attempted 3 times, but it failed each time. Common reasons that runbook jobs fail can be found here: https://docs.microsoft.com/en-us/azure/automation/automation-troubleshooting-automation-errors
Can someone help me figure out what I'm doing wrong here?
Thanks for all help provided!
Beta Was this translation helpful? Give feedback.
All reactions