Skip to content

Repository files navigation

Microsoft Graph PowerShell
Microsoft Graph PowerShell

Consume Microsoft Graph resources directly from your PowerShell scripts

The Microsoft Graph PowerShell SDK is made up of a set of modules that enable you to interact with the Microsoft Graph API using PowerShell commands. The modules consist of commands that act as wrappers for the API, allowing you to access all the features and functionality of the API through PowerShell.

Modules | Getting Started | API Version | Notes | Troubleshooting | Known Issues | Feedback | License

Upcoming browser-based interactive sign-in security change

Important

Starting February 23, 2027 at 11:00 a.m. Pacific Standard Time (7:00 p.m. Coordinated Universal Time), Microsoft plans to require a more secure browser response for interactive sign-in through the default Microsoft Graph PowerShell application.

You must upgrade to Microsoft Graph PowerShell version 2.37.0 or later before enforcement if all the following conditions apply:

  • You use Microsoft Graph PowerShell version 2.36.0 or earlier.
  • You use browser-based interactive sign-in.
  • You use the default Microsoft Graph PowerShell application.

Otherwise, sign-in or reauthentication will fail and Microsoft Graph PowerShell won't obtain an access token. Windows brokered sign-in, device code authentication, application-only authentication, customer-owned application registrations, and access tokens supplied by the caller aren't directly affected.

For update instructions, see Updating the SDK.

Modules

This repository publishes complete bundle modules, the authentication module, and scenario-specific modules for the Microsoft Graph v1.0 and beta endpoints. For faster installation and import, prefer the scenario-specific modules you need instead of the complete Microsoft.Graph and Microsoft.Graph.Beta bundle modules. The bundle modules install all their respective scenario-specific modules as dependencies.

Module Latest Preview
Microsoft.Graph Microsoft.Graph -
Microsoft.Graph.Beta Microsoft.Graph.Beta -
Microsoft.Graph.Authentication Microsoft.Graph.Authentication -
Microsoft.Graph.Applications Microsoft.Graph.Applications -
Microsoft.Graph.Bookings Microsoft.Graph.Bookings -
Microsoft.Graph.Calendar Microsoft.Graph.Calendar -
Microsoft.Graph.ChangeNotifications Microsoft.Graph.ChangeNotifications -
Microsoft.Graph.CloudCommunications Microsoft.Graph.CloudCommunications -
Microsoft.Graph.Compliance Microsoft.Graph.Compliance -
Microsoft.Graph.CrossDeviceExperiences Microsoft.Graph.CrossDeviceExperiences -
Microsoft.Graph.DeviceManagement Microsoft.Graph.DeviceManagement -
Microsoft.Graph.DeviceManagement.Administration Microsoft.Graph.DeviceManagement.Administration -
Microsoft.Graph.DeviceManagement.Enrollment Microsoft.Graph.DeviceManagement.Enrollment -
Microsoft.Graph.DeviceManagement.Functions Microsoft.Graph.DeviceManagement.Functions -
Microsoft.Graph.Devices.CloudPrint Microsoft.Graph.Devices.CloudPrint -
Microsoft.Graph.Devices.CorporateManagement Microsoft.Graph.Devices.CorporateManagement -
Microsoft.Graph.Devices.ServiceAnnouncement Microsoft.Graph.Devices.ServiceAnnouncement -
Microsoft.Graph.DirectoryObjects Microsoft.Graph.DirectoryObjects -
Microsoft.Graph.Education Microsoft.Graph.Education -
Microsoft.Graph.Files Microsoft.Graph.Files -
Microsoft.Graph.Groups Microsoft.Graph.Groups -
Microsoft.Graph.Identity.DirectoryManagement Microsoft.Graph.Identity.DirectoryManagement -
Microsoft.Graph.Identity.Governance Microsoft.Graph.Identity.Governance -
Microsoft.Graph.Identity.SignIns Microsoft.Graph.Identity.SignIns -
Microsoft.Graph.Mail Microsoft.Graph.Mail -
Microsoft.Graph.Notes Microsoft.Graph.Notes -
Microsoft.Graph.People Microsoft.Graph.People -
Microsoft.Graph.PersonalContacts Microsoft.Graph.PersonalContacts -
Microsoft.Graph.Planner Microsoft.Graph.Planner -
Microsoft.Graph.Reports Microsoft.Graph.Reports -
Microsoft.Graph.SchemaExtensions Microsoft.Graph.SchemaExtensions -
Microsoft.Graph.Search Microsoft.Graph.Search -
Microsoft.Graph.Security Microsoft.Graph.Security -
Microsoft.Graph.Sites Microsoft.Graph.Sites -
Microsoft.Graph.Teams Microsoft.Graph.Teams -
Microsoft.Graph.Users Microsoft.Graph.Users -
Microsoft.Graph.Users.Actions Microsoft.Graph.Users.Actions -
Microsoft.Graph.Users.Functions Microsoft.Graph.Users.Functions -
Microsoft.Graph.Beta.Applications Microsoft.Graph.Beta.Applications -
Microsoft.Graph.Beta.Bookings Microsoft.Graph.Beta.Bookings -
Microsoft.Graph.Beta.Calendar Microsoft.Graph.Beta.Calendar -
Microsoft.Graph.Beta.ChangeNotifications Microsoft.Graph.Beta.ChangeNotifications -
Microsoft.Graph.Beta.CloudCommunications Microsoft.Graph.Beta.CloudCommunications -
Microsoft.Graph.Beta.Compliance Microsoft.Graph.Beta.Compliance -
Microsoft.Graph.Beta.CrossDeviceExperiences Microsoft.Graph.Beta.CrossDeviceExperiences -
Microsoft.Graph.Beta.DeviceManagement Microsoft.Graph.Beta.DeviceManagement -
Microsoft.Graph.Beta.DeviceManagement.Administration Microsoft.Graph.Beta.DeviceManagement.Administration -
Microsoft.Graph.Beta.DeviceManagement.Enrollment Microsoft.Graph.Beta.DeviceManagement.Enrollment -
Microsoft.Graph.Beta.DeviceManagement.Functions Microsoft.Graph.Beta.DeviceManagement.Functions -
Microsoft.Graph.Beta.Devices.CloudPrint Microsoft.Graph.Beta.Devices.CloudPrint -
Microsoft.Graph.Beta.Devices.CorporateManagement Microsoft.Graph.Beta.Devices.CorporateManagement -
Microsoft.Graph.Beta.Devices.ServiceAnnouncement Microsoft.Graph.Beta.Devices.ServiceAnnouncement -
Microsoft.Graph.Beta.DirectoryObjects Microsoft.Graph.Beta.DirectoryObjects -
Microsoft.Graph.Beta.Education Microsoft.Graph.Beta.Education -
Microsoft.Graph.Beta.Files Microsoft.Graph.Beta.Files -
Microsoft.Graph.Beta.Financials Microsoft.Graph.Beta.Financials -
Microsoft.Graph.Beta.Groups Microsoft.Graph.Beta.Groups -
Microsoft.Graph.Beta.Identity.DirectoryManagement Microsoft.Graph.Beta.Identity.DirectoryManagement -
Microsoft.Graph.Beta.Identity.Governance Microsoft.Graph.Beta.Identity.Governance -
Microsoft.Graph.Beta.Identity.SignIns Microsoft.Graph.Beta.Identity.SignIns -
Microsoft.Graph.Beta.Mail Microsoft.Graph.Beta.Mail -
Microsoft.Graph.Beta.ManagedTenants Microsoft.Graph.Beta.ManagedTenants -
Microsoft.Graph.Beta.Migrations Microsoft.Graph.Beta.Migrations -
Microsoft.Graph.Beta.Notes Microsoft.Graph.Beta.Notes -
Microsoft.Graph.Beta.People Microsoft.Graph.Beta.People -
Microsoft.Graph.Beta.PersonalContacts Microsoft.Graph.Beta.PersonalContacts -
Microsoft.Graph.Beta.Planner Microsoft.Graph.Beta.Planner -
Microsoft.Graph.Beta.Reports Microsoft.Graph.Beta.Reports -
Microsoft.Graph.Beta.SchemaExtensions Microsoft.Graph.Beta.SchemaExtensions -
Microsoft.Graph.Beta.Search Microsoft.Graph.Beta.Search -
Microsoft.Graph.Beta.Security Microsoft.Graph.Beta.Security -
Microsoft.Graph.Beta.Sites Microsoft.Graph.Beta.Sites -
Microsoft.Graph.Beta.Teams Microsoft.Graph.Beta.Teams -
Microsoft.Graph.Beta.Users Microsoft.Graph.Beta.Users -
Microsoft.Graph.Beta.Users.Actions Microsoft.Graph.Beta.Users.Actions -
Microsoft.Graph.Beta.Users.Functions Microsoft.Graph.Beta.Users.Functions -
Microsoft.Graph.Beta.WindowsUpdates Microsoft.Graph.Beta.WindowsUpdates -

Getting Started

1. Installation

PowerShell 7 or later is recommended on all platforms. Install the modules you need from PowerShell Gallery. For the examples below:

Install-Module Microsoft.Graph.Users -Scope CurrentUser
Install-Module Microsoft.Graph.Applications -Scope CurrentUser

These modules automatically install Microsoft.Graph.Authentication, which provides Connect-MgGraph. To install all v1.0 modules instead, use Install-Module Microsoft.Graph -Scope CurrentUser.

If you encounter command name conflicts when upgrading from v1.x to v2.x, use -AllowClobber and -Force:

Install-Module Microsoft.Graph -AllowClobber -Force

See Install the Microsoft Graph PowerShell Module guide for detailed installation instructions.

2. Authentication

The module supports two main types of authentication:

Delegated access

Get access to Microsoft Graph resources on behalf of a user. Request only the delegated permissions needed for your operations; some permissions require administrator consent.

# Using interactive authentication.
Connect-MgGraph -Scopes "User.ReadBasic.All", "Application.ReadWrite.All"

On Windows, interactive sign-in uses Web Account Manager (WAM) by default. -LoginHint "user@contoso.com" can pre-populate the account for interactive sign-in; it does not guarantee a prompt-free sign-in. For device code authentication, use -UseDeviceCode.

Delegated sign-in uses the CurrentUser token cache by default, so it can persist across PowerShell sessions. Use -ContextScope Process to keep tokens in the current process instead; this does not select a different account. Inspect the connected account, tenant, and permissions with Get-MgContext.

App-only access (client credentials grant flow)

Get access to Microsoft Graph resources using an application's identity, not on behalf of a user. Configure the required application permissions and grant administrator consent before connecting.

# Using -CertificateThumbprint
Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -CertificateThumbprint "YOUR_CERT_THUMBPRINT"

See Authentication for client secret, managed identity, custom application, sovereign cloud, and WAM configuration examples.

3. List users in your tenant

Get-MgUser -Top 10 -Property Id, DisplayName, BusinessPhones | Format-Table Id, DisplayName, BusinessPhones

4. Filter a user in your tenant

$User = Get-MgUser -Filter "displayName eq 'Megan Bowen'"

5. Create a new app registration

New-MgApplication -DisplayName "ScriptedGraphPSApp" `
                  -SignInAudience "AzureADMyOrg" `
                  -Web @{ RedirectUris = "https://localhost"}

6. Sign out of the current authentication context

Disconnect-MgGraph

This clears the SDK's in-memory authentication state and, for CurrentUser, clears persisted tokens for the session's account when it can be identified. It does not clear the Windows WAM broker cache by default. See Sign out and token caching before using -SignOutFromBroker.

API Version

Use v1.0 APIs for production scripts. Beta APIs are preview features and can introduce breaking changes. Install the beta scenario-specific modules you need (or Microsoft.Graph.Beta for all beta modules); v1.0 and beta modules can coexist and share authentication.

Install-Module Microsoft.Graph.Beta.Users -Scope CurrentUser
# Consume Microsoft Graph beta resources.
Connect-MgGraph -Scopes "User.ReadBasic.All"
$Users = Get-MgBetaUser

Notes

Update Schedule

The Microsoft Graph PowerShell SDK is scheduled to be updated during the fourth week of each month

Upgrading to v2

The following breaking changes have been introduced between v1.x and v2.x:

  • Dropped profile support.
  • Dropped support for -ForceRefresh on Connect-MgGraph.
  • Renamed beta command names from <Verb>-Mg<Noun> to <Verb>-MgBeta<Noun>.
  • Renamed DeviceManagement.Enrolment module to DeviceManagement.Enrollment.
  • Moved directory role and entitlement management commands from DeviceManagement.Enrollment to Identity.Governance module.
  • Changed beta namespace from Microsoft.Graph.PowerShell.Models.<Entity> to Microsoft.Graph.Beta.PowerShell.Models.<Entity>.
  • Changed -AccessToken type on Connect-MgGraph from String to SecureString.

See the v2 upgrade guide for more details.

Troubleshooting

Permission Related Errors

When working with various operations in the Graph, you may encounter an error such as "Insufficient privileges to complete the operation." For example, this particular error can occur when using the New-MgApplication command if the appropriate permissions are not granted.

Check the tenant, authentication type, and granted permissions with Get-MgContext. Delegated access also depends on the signed-in user's privileges; app-only access requires application permissions with administrator consent. After permissions or consent change, allow time for propagation, then run Disconnect-MgGraph and reconnect with the required scopes or app credentials. Caller-provided access tokens must be replaced by the caller.

See Microsoft Graph API Permissions Reference for more details.

Common Errors

See our troubleshooting guide for a detailed view of how to troubleshoot common errors when using Microsoft Graph.

Known Issues

  • Using the -Property {PropertyName} parameter will not select the property as the output of the command. All commands return CLR objects, and customers should pipe the command outputs to Format-Table or Select-Object to return individual properties.

  • Customers upgrading from previous versions of the SDK may encounter authentication prompts on every command call. Start by running Disconnect-MgGraph, then reconnect with Connect-MgGraph. Do not delete the entire .mg directory: it also contains SDK options and environment settings. For Windows broker sign-in issues, see WAM guidance, including the custom -ClientId requirement when disabling WAM.

Feedback

If you find any bugs when using the Microsoft Graph PowerShell modules, please file an issue on our GitHub issues page.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.

Releases

Packages

Used by

Contributors

Languages