It seems you need to use a non-interactive login, follow the steps as below.
1.Create an Azure Active Directory application and create a secret for the app, save the secret and get values for signing in.
2.In your AD App -> API permissions
-> Add a permission
-> select Azure Active Directory Graph
-> Application permissions
-> Directory.Read.All
-> click Add permissions
-> click Grant admin consent for xxx
, refer to the screenshot.


3.Try the script as below, use the values which you get in step 1, it works fine on my side.
Note: You need to use the Task version
with 4.*(preview)
when you use Az
powershell module.
$azureAplicationId ="<your ad app application id>"
$azureTenantId= "<your tenant id>"
$azurePassword = ConvertTo-SecureString "<the secret of your ad app>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
Get-AzADGroup

organizationname-projectname-513f22f1-befd-xxxxxxcfe90f
in the App Registerations in your tenant. But you also need the permission toGrant admin consent for xxx
. May be you could ask your admin to grant the api permission for you.:-) – Joy Wang-MSFT