Connect to Microsoft365 using Microsoft Graph PowerShell

Target

This article is for customers who wish to federate Microsoft 365 and HENNGE Access Control with Microsoft Graph PowerShell.

Purpose

This article describes how to connect to Microsoft 365 through PowerShell on your terminal, enabling you to manage your tenant.

Cautions

1. You will need to install a module to connect to Microsoft365 from a PowerShell application on your terminal.

2. The account information of the global administrator in your Microsoft 365 tenant is required.

3. The content of this article is based on product specifications as of April 2024 and is revised accordingly without advanced notice.

 

Procedures

Prerequisites

1. The Microsoft Graph PowerShell SDK module is needed. Please make sure that the following is completed in advance:

Installation of the Microsoft Graph PowerShell SDK

1. Connection to Microsoft 365 through Microsoft Graph PowerShell

1-1. Open Windows [ Start ] and open [ Windows PowerShell ] with administrator privileges

* Check if "Administrator" is displayed in the upper left corner of the PowerShell.

pwsh-admin.png

1-2.  Execute the following command:

Connect-MgGraph

* If an error is printed in red as a result of executing the command, please refer to the following.

Workaround for TLS 1.0 / TLS 1.1 errors when running Microsoft Graph PowerShell

14855969295641_1-2.png

1-3.  You will be prompted for Microsoft 365 credentials, so enter the account information of the global administrator in your Microsoft 365 tenant.

sign-in.png

1-4.  Check if you are connected to Microsoft Graph PowerShell.

Once the connection is successfully made, the message [ Welcome To Microsoft Graph ! ] will appear on your terminal.

14840590341401_4-2.png

2. (Optional) To check for a successful connection, run the following command and verify that the results are displayed.

Get-MgUser

If successful, you will see a list of users on the Microsoft 365 tenant as the result of the command.

14855969295641_2.png

* With Microsoft Graph PowerShell, the command may fail if the necessary permissions are not granted. If this is the case, please grant the following permissions with the command in Section 1-2. and try again.

Connect-MgGraph -Scopes "Organization.Read.All"

3. Disconnect from Microsoft Graph

Disconnect from Microsoft Graph by executing the following command.

Disconnect-MgGraph

* With [ Connect-MgGraph ] command, your previously authenticated credentials will be retained and you will not be required to sign in again in the next time it is invoked. Therefore, it is necessary to perform a [ Disconnect-MgGraph ] to ensure that sign-in is disconnected.

Reference

          
Was this article helpful?