Installing MS Graph PowerShell Module

Introduction

Recently, MSFT introduced the Graph PowerShell module. Since then, it has been encouraging all applications to authenticate using MS Graph. In simple words, Microsoft Graph serves as an entry point for authentication and authorization of all the applications inside M365. More about the MS graph can be found in the references section. In this article, we will focus on how to install Graph PowerShell Module on a Windows 11 machine.

First, let’s validate that no modules of MS graph are installed in your machine. This can be verified by running the below command:

Get-InstalledModuleMicrosoft.Graph

If the output has an error message that says "No Match was found for the specified search criteria and module names 'Microsoft. Graph'," this confirms that Graph PowerShell module is not installed on your machine.

Pre-requisites

A PowerShell version greater than five is required to install this module.

Steps

Let’s follow the steps below to install the MS Graph PowerShell module.

Step 1

Run the below command to install the latest version of Graph PowerShell module from the PS repository.

Install-Module Microsoft.Graph -Scope AllUsers

In some cases you may not have admin rights to install for all users. If so, try modifying the scope to current user by running the command below.

Install-Module Microsoft.Graph -Scope CurrentUser

You should be seeing the below message, asking to confirm if you are sure about installing the Graph PowerShell module from untrusted repository. Click on "Yes."

Step 2

It might take some time to complete the module installation. Observe the messages below. They will update you about the progress of the installation.

After 5 to 10 minutes, depending on the resources utilization, you should see that the operation is complete.

Step 3

Now, validate the version of the MS Graph module installed by running the same command on validation.

Get-InstalledModule Microsoft.Graph

Step 4

Go to Azure AD and look for Enterprise Applications. Search for “Microsoft Graph Powershell’ module and validate if admin consent is granted for basic read profiles for all applications.

Step 5

Click on the "Microsoft Graph PowerShell" module and click on the "Permissions."

Step 6

Check for permissions for the App. It is required for a global admin to click on ‘Admin Consent’ at least once in order to perform basic read operations using Graph PowerShell Module.

If you see that the permission scope is blank, click on the "Grant admin consent" button. It should ask for confirmation, as shown below.

Step 7

Now, get back to the PowerShell window and connect to the MS Graph module. Please note that while connecting to the MS Graph module, you must define the scope. For instance, the below PS command connects to the MS Graph module with scope to read basic signed-in user profiles and read all applications.

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

The below PS Command defines the scope to read all user profiles and all applications.

Connect-MgGraph -Scopes "User.Read.all","Application.Read.All"

In both cases, you must get consent similar to that below, and on accepting it, you will be connected to Graph Module.

Step 8

Try running the below PS command to get the profile information of the signed-in user. Replace the user ID with the user ID from your tenant.

Get-MgUser -UserId 'vinaya@contosodev.onmicrosoft.com'

Get-MgUser -UserId 'vinaya@contosodev.onmicrosoft.com' | select *

The select * will give you complete details.

Similarly, you can run Get-MgUser PS command, if the scope is defined for ‘User.Read.All’.

Get-MgUser

Complete Script

#Getting the version of MS graph module
Get-InstalledModule Microsoft.Graph

#Install the Graph PS module for all the users
Install-Module Microsoft.Graph -Scope AllUsers

#Connect to Graph Module with required scopes
Connect-MgGraph -Scopes "User.Read.all","Application.Read.All"

#Get user information using Get-MgUser
Get-MgUser -UserId 'vinaya@contosodev.onmicrosoft.com' | select *

#Get all the users information
Get-MgUser

#Disconnect Graph Session
Disconnect-MgGraph

Conclusion

In this article you have seen how to install the MS Graph PowerShell module and how to configure your tenant with required permissions to get started with PowerShell Graph SDK.

References