command-line-interfaceazure-ad-b2bazure-cloud-shell

Get groups user is memberof azure cli


To know whether the user is a part of any Azure ad group or not I used below Azure cli command

az ad group member check --group groupname --member-id ******

This gave me output with warning like below:

az : WARNING: The underlying Active Directory Graph API will be replaced by Microsoft Graph API in Azure CLI 2.37.0. Please carefully review all breaking changes introduced during this migration:  
https://learn.microsoft.com/cli/azure/microsoft-graph-migration
At line:1 char:1  
+ az ad group member check --group *** --member-id **** ...  
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
+ CategoryInfo  : NotSpecified: (WARNING: The un...graph-migration:String) [], RemoteException  
+ FullyQualifiedErrorId : NativeCommandError  
 
{  
"odata.metadata": "https://graph.windows.net/******/$metadata#Edm.Boolean"  
"value": true  
}

For every command I am running in cli I get this warning which annoys me. How to get rid of the warning and get only the output?

I also want to get the list of groups the user is a memberof? Is there any command to achieve that in cli?


Solution

  • I tried to reproduce the same in my environment like below:

    To avoid the warning message, please use --only-show-errors command like below:

    az ad group member check --group Test_Group1 --member-id User_Object_ID --only-show-errors
    

    Response (Without warning):

    {  
    "odata.metadata":https://graph.windows.net/XXXX/$metadata#Edm.Boolean" 
    "value": true  
    }
    

    enter image description here

    To get the list of groups the user is a memberof, please use the below command:

    az ad user get-member-groups --id User_Object_ID  --only-show-errors
    

    enter image description here

    Reference:

    az ad user | Microsoft Docs