title: Read AD group from azure function using service principal authentication
body: <p>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):</p>
  
  <pre><code>System.Management.Automation.RemoteException: Error occurred while executing GetGroups 
  Code: Authorization_RequestDenied
  Message: Insufficient privileges to complete the operation.
  RequestId: &lt;requestID&gt;
  DateTimeStamp: Mon, 14 Oct 2019 20:40:26 GMT
  HttpStatusCode: Forbidden
  HttpStatusDescription: Forbidden
  HttpResponseStatus: Completed
  </code></pre>
  
  <p>Why is that happening? did anyone use azuread module commands within azure function? I have granted ms graph permissions for this app:
  <a href="https://i.stack.imgur.com/c77VW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c77VW.png" alt="enter image description here"></a></p>
  
  <pre><code>$Script={
      param ()
      ##Save AzureAD module to the modules folder before publishing
      Import-Module .\modules\AzureAD
  
      $appId = "&lt;AppId&gt;"
      $thumb = "&lt;CertThumb&gt;"
      $tenantId = "TenantID"
      Connect-AzureAD -TenantId $tenantId -ApplicationId  $appId -CertificateThumbprint $thumb
  
      $groupName = "&lt;Name of the group&gt;"
  
      $group = Get-AzureADGroup -SearchString $groupName 
      #or
      #$group = Get-AzureADGroup -ObjectId "&lt;object id&gt;"
  
      echo $group
  }
  
  &amp;$env:64bitPowerShellPath -WindowStyle Hidden -NonInteractive -Command $Script
  </code></pre>
  
  <p>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: 
  <a href="https://github.com/Azure/azure-functions-powershell-worker/issues/232" rel="nofollow noreferrer">https://github.com/Azure/azure-functions-powershell-worker/issues/232</a></p>