Use Pnp.PowerShell with user assigned managed identity in Azure automation accounts #3021
Unanswered
carsten-blanke
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Maybe there is an article or tutorial like this, I didn't find it, so I decided to post it here.
My goal was to use the PnP:PowerShell module in a runbook in an automation account. I want to change lockstates in personal sharepoint sites (OneDrive for business). Because I hate to change outdated secrets and/or certificates, I wanted to run it with a managed identity. For reasons of company guidelines I had to use user assigned managed identity.
To show how I managed it, I'll show you first the end of my implementation: The Login in the runbook:
Connect-PnPOnline -ManagedIdentity -UserAssignedManagedIdentityClientId "<app id of mi>" -Url "https://tenant-admin.sharepoint.com"
To achieve this, I used the following steps:
Step 1: Create an user assigned managed identity and assign it to the runbook
Step 2: Each managed identity is represented by an enterprise application in the azure active directory. Usually you can give only app registrations permissions. To give an enterprise app permissions, you have to use PowerShell. The work to do is, to give the MI the Graph permission "Sites.FullControl.All" and the Sharepoint permission "Sites.FullControl.All". You can use this script if you want.
Be aware that you have to be global admin to use this script.
Step 3: You have to invite the MI in the sharepoint tenant and give FullControl to it.
Open the site https://tenant-admin.sharepoint.com/_layouts/15/appinv.aspx
On the site post the Appid of the MI into the textbox and click "Lookup"
Some fields will get values. Do not change them! Paste this XML unchanged into the permission field
Click "create" and then "trust".
Step 4: Step back and enjoy. You can now use the MI in runbooks an login like above.
Beta Was this translation helpful? Give feedback.
All reactions