How To Setup MSGraph CLI And Fetch All The Users In The Tenant

Introduction

Command-line tool for interacting with Microsoft graph is in its early stage called Microsoft Graph CLI. So in this blog, we will understand how we can install and use Microsoft Graph CLI in our development environment.

To install Microsoft Graph CLI we have two different options,

  1. Using Winget
  2. Using Direct release download

We will go through both the installation in detail.

Using Winget

Winget is a client interface to Windows Package Manager service to install Winget tool in Windows 10 environment download from the below link.

Link to download Winget:- Link

How To Setup MSGraph CLI And Fetch All The Users In The Tenant

Note
For the first install, the button would display Text as Install. Click on Install for completing the installation.

Once the winget is installed we need to open a command prompt and run the below command to install Microsoft Graph CLI which becomes very easy as everything would be taken care of by Winget. Before installing we should search if the package is available or not using the below command,

winget search microsoft.msgraphcli

How To Setup MSGraph CLI And Fetch All The Users In The Tenant

For installing use the below command,

winget install microsoft.msgraphcli

Using Direct release Download

Direct download and installing is very easy and straightforward. It has a similar experience as what we have while installing other windows based applications.

Click on this link to navigate to the release of MS Graph CLI.

Download the file named Microsoft.Graph.CLI.msi and double click on it to install click on next and finish the installation.

How To Setup MSGraph CLI And Fetch All The Users In The Tenant

Fetch all users in Tenant Using Microsoft Graph CLI

To fetch all the users first let us login to Microsoft Graph CLI so that we can work with Graph APIs to login using the below command,

mgc login --scopes "user.read.all"

Note
We can use different scopes as per our requirement but for this example, as we only require the user.read.all,

How To Setup MSGraph CLI And Fetch All The Users In The Tenant

How To Setup MSGraph CLI And Fetch All The Users In The Tenant

To fetch all the users just a single line of command to fetch all the users.

mgc users user list --query "[].{name: displayName, email: mail}" --output table

Note
We can fetch other properties as per our requirement but for this example, we have used displayName and email.

How To Setup MSGraph CLI And Fetch All The Users In The Tenant

Conclusion

Microsoft Graph CLI is still a work in the process there would be more operations coming up and this would be one of the easiest ways to use Microsoft Graph data and to automate processes using CLI. For more details please check the GitHub repository link.