Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Get-PnPGroup and Get-PnPGroupMember in Azure Automation runbook with System-Assigned Managed Identity throw a Not Authorized error #4766

Open
1 of 6 tasks
dgwebb opened this issue Feb 27, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@dgwebb
Copy link

dgwebb commented Feb 27, 2025

I have an Azure automation runbook using a system-assigned Managed Identity.

When the runbook executes a Get-PnPGroup or Get-PnPGroupMember cmdlet, a "401 unauthorized" error is returned.

BTW, the same issue occurs with Get-PnPSiteCollectionAdmin.

Expected behavior

"Get-PnPGroup" returns a list of the SharePoint groups in the connected site collection.
"Get-PnPGroupMember -Group XXX" returns a list of the members in SharePoint group XXX.

Actual behavior

Response received:
{"odata.error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}}}

Steps to reproduce behavior

  1. Create an Azure automation account.
  2. Create a system-assigned managed identity.
  3. Grant the following permissions to the managed identity:

Sites.Read.All (SharePointOnline)
User.Read.All (Graph)
Group.Read.All (Graph)
GroupMember.Read.All (Graph)

  1. Create a runbook (runtime environment PowerShell 7.2)
  2. Enter the following runbook script:

$siteUrl = "... url here ..."
Connect-PnPOnline $siteUrl -ManagedIdentity
$groups = Get-PnPGroup # Error will occur on this statement

What is the version of the Cmdlet module you are running

2.12.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : Azure Automation runbook
@dgwebb dgwebb added the bug Something isn't working label Feb 27, 2025
@dgwebb dgwebb changed the title [BUG] Get-PnPGroup and Get-PnPGroupMember do not work with managed identity in Azure Automation runbook [BUG] Get-PnPGroup and Get-PnPGroupMember in Azure Automation runbook with System-Assigned Managed Identity throw a Not Authorized error Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant