Skip to content

Using Managed Identity in Azure Automation Runbook to connect to SharePoint Online #2568

@joostvdlinden

Description

@joostvdlinden

Discussed in #2559

Originally posted by joostvdlinden November 16, 2022
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:

  • Microsoft Graph - Group.Read.All | Application type
  • Microsoft Graph - User.Read.All | Application type
  • Microsoft Graph - Sites.FullControl.All | Application type
  • Office 365 SharePoint Online - Sites.FullControl.All | Application type

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..

Connect-PnPOnline -Url orgname.sharepoint.com -ManagedIdentity

Get-PnPTenantSite -Identity "https://orgname.sharepoint.com/sites/TestSite"

Disconnect-PnPOnline

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

Connect-PnPOnline -Url "https://orgname.sharepoint.com/sites/TestSite" -ManagedIdentity

Get-PnPSite

Disconnect-PnPOnline

Can someone help me figure out what I'm doing wrong here?

Thanks for all help provided!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions