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:
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:
Then deployed to Azure.
Now, Given Share Point Admin Role for the function app:
Also have below permissions:
Output:
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.