How to Use Microsoft Graph Command Line Tools: Complete Step-by-Step Guide

Microsoft Graph command line tools allow administrators and developers to manage Microsoft 365 services such as Azure Active Directory, Teams, SharePoint, Outlook, and OneDrive directly from the terminal. Instead of relying on multiple portals or custom applications, these tools provide a unified, scriptable way to access Microsoft cloud data and automate tasks at scale.

How to Use Microsoft Graph Command Line Tools: Complete Step-by-Step Guide
How to Use Microsoft Graph Command Line Tools: Complete Step-by-Step Guide

What You Need Before You Start

Before using Microsoft Graph tools, ensure you have:

  • A Microsoft 365 or Azure AD account
  • Admin permissions (recommended for most operations)
  • Windows, macOS, or Linux system
  • Internet access
  • Basic familiarity with command-line usage

No advanced programming knowledge is required.

PlayStation Portal Remote Player

-11% $178.99 $199.99
Stream PS5 games to an 8” 1080p screen.
Platform: PlayStation 5 Color: White
Hurry — Deal Ending Soon on Amazon
20K+ bought in past month.

Tool 1: Microsoft Graph Explorer (Start Here)

Before running automation scripts, Microsoft strongly recommends testing API requests. This is where Microsoft Graph Explorer plays a critical role.

Although it is not a traditional CLI, Graph Explorer is an essential Graph tool used for validation and troubleshooting.

How to Use Microsoft Graph Explorer for API Testing

Microsoft Graph Explorer is a web-based interface that allows you to test Microsoft Graph API endpoints safely before using them in scripts or command-line tools.

Why Graph Explorer Is Important

Graph Explorer helps you:

  • Test Graph API endpoints
  • Verify required permissions (scopes)
  • Preview JSON responses
  • Detect authentication or access issues
  • Validate POST, PATCH, and DELETE operations

Skipping this step often leads to permission errors and broken automation later.

How to Access Microsoft Graph Explorer

  1. Open Microsoft Graph Explorer in your browser
  2. Sign in using your Microsoft 365 or Azure AD account
  3. Grant permissions when prompted

No installation is required.

Example API Test

To retrieve users from your tenant:

GET https://graph.microsoft.com/v1.0/users

Graph Explorer shows:

  • Response status
  • Data structure
  • Required permissions
  • Error messages (if any)

Once verified, this same request can be used in CLI or PowerShell tools.

Tool 2: Microsoft Graph CLI (mgc)

The Microsoft Graph CLI (mgc) provides direct command-line access to Microsoft Graph REST APIs. It is cross-platform and designed for developers, DevOps engineers, and advanced admins.

How to Install Microsoft Graph CLI

Windows (Winget)

winget install Microsoft.GraphCLI

macOS (Homebrew)

brew install microsoftgraph/tap/msgraph

Linux

curl -sL https://aka.ms/InstallMicrosoftGraphCli | bash

Verify installation:

mgc --version

How to Sign In to Graph CLI

mgc login

A browser window opens for authentication. Permissions are securely cached after login.

Running Your First Graph CLI Command

List users:

mgc users list

Get a specific user:

mgc users get --user-id [email protected]

Filter results:

mgc users list --filter "accountEnabled eq true" --select id,displayName,mail

When to Use Microsoft Graph CLI

  • Testing validated API endpoints
  • Fetching tenant data
  • DevOps and CI/CD pipelines
  • Cross-platform scripting

Tool 3: Microsoft Graph PowerShell SDK

The Microsoft Graph PowerShell SDK is the preferred replacement for legacy AzureAD and MSOnline modules. It integrates deeply with Windows admin workflows.

How to Install Microsoft Graph PowerShell

Open PowerShell as Administrator:

Install-Module Microsoft.Graph -Scope CurrentUser

Verify installation:

Get-InstalledModule Microsoft.Graph

Connecting to Microsoft Graph in PowerShell

Connect-MgGraph

To limit permissions:

Connect-MgGraph -Scopes "User.Read.All","Group.Read.All"

Check connection:

Get-MgContext

Common PowerShell Commands

Get all users:

Get-MgUser

Get a specific user:

Get-MgUser -UserId [email protected]

When to Use Graph PowerShell

  • User lifecycle management
  • License automation
  • Security audits
  • Enterprise-scale scripting

Tool 4: Microsoft 365 CLI (m365)

The Microsoft 365 CLI is built on top of Microsoft Graph and other Microsoft 365 APIs. It simplifies tenant-level administration across Teams, SharePoint, OneDrive, and Outlook.

How to Install Microsoft 365 CLI

npm install -g @pnp/cli-microsoft365

Verify:

m365 version

Logging In to Microsoft 365 CLI

m365 login

Supported login methods include browser authentication, device code, and certificates.

Common Microsoft 365 CLI Commands

List Teams:

m365 teams team list

List SharePoint sites:

m365 spo site list

Create a Team:

m365 teams team add --name "IT Support"

Recommended Microsoft Graph Workflow (Best Practice)

For reliable automation, follow this workflow:

  1. Test APIs in Microsoft Graph Explorer
  2. Execute validated requests using Graph CLI
  3. Automate with PowerShell or Microsoft 365 CLI

This approach minimizes errors and prevents permission-related failures.

How Each Microsoft Graph Tool Is Used in Practice

ToolPrimary Purpose
Microsoft Graph ExplorerAPI testing and validation
Microsoft Graph CLIDirect Graph API execution
Graph PowerShell SDKAdmin automation
Microsoft 365 CLIProductivity and tenant management

Most organizations use multiple tools together, not just one.

Common Mistakes to Avoid

  • Skipping API testing
  • Using deprecated AzureAD modules
  • Granting excessive permissions
  • Running unfiltered queries on large tenants

Always log out when finished:

mgc logout
m365 logout

Why Microsoft Graph Tools Matter Today

Microsoft is consolidating all cloud service APIs under Microsoft Graph. Legacy APIs and modules are being deprecated in favor of Graph-based tools that offer better security, scalability, and consistency.

Learning these tools is now a core skill for Microsoft 365 administrators.

FAQs Microsoft Graph Command Line Tools

What are Microsoft Graph command line tools?

Microsoft Graph command line tools are utilities that let you manage Microsoft 365 services using the terminal. They allow you to access users, groups, Teams, SharePoint, and other data through Microsoft Graph without building full applications.

Which Microsoft Graph command line tool should beginners start with?

Beginners should start with Microsoft Graph Explorer. It helps test API requests, understand permissions, and preview responses before using CLI or PowerShell tools.

Is Microsoft Graph CLI different from Microsoft 365 CLI?

Yes. Microsoft Graph CLI provides direct access to Graph API endpoints, while Microsoft 365 CLI focuses on simplified admin tasks for Teams, SharePoint, and other Microsoft 365 services.

Do I need admin access to use Microsoft Graph command line tools?

Some commands require admin permissions, especially for managing users, licenses, or security settings. Read-only queries may work with standard user permissions, depending on the scope.

Is Microsoft Graph PowerShell replacing AzureAD and MSOnline modules?

Yes. Microsoft Graph PowerShell SDK is the official replacement for AzureAD and MSOnline modules, which are being deprecated.

Can Microsoft Graph command line tools be used on macOS and Linux?

Yes. Microsoft Graph CLI and Microsoft 365 CLI are cross-platform and work on Windows, macOS, and Linux. PowerShell also supports multiple operating systems.

Why should I use Microsoft Graph Explorer before automation?

Graph Explorer helps validate API endpoints, permissions, and responses. Testing first reduces errors, prevents permission issues, and ensures automation scripts work correctly.

Are Microsoft Graph command line tools safe to use in production?

Yes, when used correctly. Always apply the least-privilege permissions, test commands in Graph Explorer, and avoid running unfiltered queries on large tenants.

Can Microsoft Graph tools be used for automation and CI/CD?

Yes. Microsoft Graph CLI and PowerShell SDK are commonly used in automation scripts and CI/CD pipelines to manage Microsoft 365 environments programmatically.

Are Microsoft Graph command line tools free to use?

Yes. The tools are free, but you must have a valid Microsoft 365 or Azure AD tenant to access data through Microsoft Graph.

Microsoft Graph command line tools provide a powerful, unified way to manage Microsoft 365 environments. By combining Graph Explorer for testing, CLI tools for execution, and PowerShell for automation, you gain full control over your tenant with fewer errors and less manual work.

More Tech Guides

  1. 01Best Logo Maker Tools 2026 for Professional Branding
  2. 02How to Update Graphics Driver in Windows 11 (Step-by-Step Guide)
  3. 03How to Fix DISM Does Not Support Servicing Windows PE Error in Windows
  4. 04How to Make a Minecraft Server (Java Edition Guide)
  5. 05How to Fix Warzone “Voice and Text Chat Disabled Due to Platform Restrictions” Error
  6. 06How to Install Android Fastboot Drivers on Windows 11
  7. 07How to Fix Windows 11 No Device Drivers Were Found Error During Installation
  8. 08How to Use Windows 11 KB5070307 Point-in-Time Restore and Fluid Dictation

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply