Azure function (PowerShell) - IDX12729: Unable to decode the header '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' as Base64Url encoded string.

Khalid Hajjouji 50 Reputation points
2025-04-01T12:51:11.94+00:00

I am using an Azure function with the PowerShell language. I would like to get a specific M365 group from entra Id. I am using the pnp PowerShell module. I got the error:

IDX12729: Unable to decode the header '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' as Base64Url encoded string.

This is my PowerShell command:

Connect-PnPOnline -Url "someSpUrl" -ManagedIdentity $site = Get-PnPTenantSite -Identity someSpUrl" $m365Group = Get-PnPMicrosoft365Group -Identity [System.Guid]$site.GroupId

Why do I get this error? How can I fix this?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,936 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RithwikBojja 3,055 Reputation points Microsoft External Staff Moderator
    2025-04-03T09:46:19.3933333+00:00

    Hi @Khalid Hajjouji,

    Below approach worked for me to retrieve Microsoft 365 Group :

    Firstly, created a function app in Azure. Later Enabled Managed identity as below:

    enter image description here

    Below is my function app code:

    run.ps1:

    
    using namespace System.Net
    
    param($Request, $TriggerMetadata)
    
    Connect-PnPOnline "m3542.sharepoint.com" -ManagedIdentity
    
    $site = Get-PnPTenantSite -Identity "https://m3542.sharepoint.com/sites/DemoSite" 
    
    $m365Group = Get-PnPMicrosoft365Group -Identity $site.GroupId
    
    Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    
        StatusCode = [HttpStatusCode]::OK
    
        Body = $m365Group
    
    })
    
    

    requirements.psd1:

    
    @{
    
    'PnP.PowerShell' = '2.0.45-nightly'
    
    }
    
    

    The profile.ps1 should be empty:

    enter image description here

    Then deployed to Azure.

    Now, Given Share Point Admin Role for the function app:

    enter image description here

    Also have below permissions:

    enter image description here

    Output:

    enter image description here

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.