The smarter way to manage Microsoft 365. Try AdminDroid for free!
Connect-MgGraph (Microsoft Graph) 

Connect-MgGraph (Microsoft Graph)

Summary

Connect to Microsoft Graph PowerShell using Connect-MgGraph cmdlet with appropriate permission scopes. Authenticate with user credentials, certificate-based authentication, or access tokens. Specify TenantId for multi-tenant scenarios and configure context scope for session management.

The Connect-MgGraph cmdlet is used to connect to Microsoft Graph PowerShell. You must install Microsoft Graph PowerShell SDK to use this cmdlet.

Else, you will receive the error: “The term ‘Connect-MgGraph’ is not recognized as the name of a cmdlet, function, script file, or operable Program”

Syntax:

Description:

The ‘Connect-MgGraph’ cmdlet initiates connection to Microsoft Graph. After successful connection, you will receive “Welcome to Microsoft Graph!” message.

Examples:

Example 1: Initiate a connection.

This command connects Microsoft Graph with “User.Read.All” permission scope. Each Graph API requires different scope permission. To identify the required scope, you can refer to the Microsoft doc.

Example 2: Connect Microsoft Graph with Tenant id

If you don’t specify the TenantId parameter, it will create a session with the last tenant you signed in.

Parameters:

-Access Token <string>

Specifies a bearer token for Microsoft Graph service. Access tokens do timeout and you’ll have to handle their refresh.

-Break

Wait for .NET debugger to attach.

-Certificate <X509Certificate2>

The Certificate parameter specifies the certificate that’s used for Certificate-based authentication (CBA). An X.509 certificate supplied during invocation.

Don’t use this parameter with the CertificateThumbprint parameter.

-CertificateName <string>

The name of your certificate. The Certificate will be retrieved from the current user’s certificate store.

-CertificateThumbprint <string>

Specifies the certificate thumbprint of a digital public key X.509 certificate of a user account that has permission to perform this action. For example, 83213AEAC56D61C97AEE5C1528F4AC5EBA7321C1.

Don’t use this parameter with the Certificate parameter.

-ClientId <string>

The client id of your application.

-Scopes <string []>

An array of delegated permissions to consent to.

-TenantId <string>

Specifies the ID of a tenant.

-UseDeviceAuthentication

Use device code authentication instead of browser control

About the author

M365Scripts Content Team is a specialized group of domain experts across Microsoft Entra, Exchange, SharePoint, Teams, Intune, Active Directory and security. Their work focuses on administration, governance, and configuration guidance that reflects real environment conditions. This helps IT teams apply settings correctly and maintain consistent operational control.

Connect-MgGraph (Microsoft Graph) 

by M365Scripts Content Team time to read: 2 min
0