I want to read and list members of a particular AD group using powershell script using azure function. To connect AD i am using service principal. Connecting to AzureAD is successful, but trying to access AD group gives me an error (at this stage i just want to get a specific group and echo it):
System.Management.Automation.RemoteException: Error occurred while executing GetGroups
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
RequestId: <requestID>
DateTimeStamp: Mon, 14 Oct 2019 20:40:26 GMT
HttpStatusCode: Forbidden
HttpStatusDescription: Forbidden
HttpResponseStatus: Completed
Why is that happening? did anyone use azuread module commands within azure function? I have granted ms graph permissions for this app:

$Script={
param ()
##Save AzureAD module to the modules folder before publishing
Import-Module .\modules\AzureAD
$appId = "<AppId>"
$thumb = "<CertThumb>"
$tenantId = "TenantID"
Connect-AzureAD -TenantId $tenantId -ApplicationId $appId -CertificateThumbprint $thumb
$groupName = "<Name of the group>"
$group = Get-AzureADGroup -SearchString $groupName
#or
#$group = Get-AzureADGroup -ObjectId "<object id>"
echo $group
}
&$env:64bitPowerShellPath -WindowStyle Hidden -NonInteractive -Command $Script
Note that my code is wrapped into $Script variable and last line is added to make the code work as a temporary workaround until AD modul will be added to PS Core: https://github.com/Azure/azure-functions-powershell-worker/issues/232
