How To Install the Microsoft Graph PowerShell Module?

Introduction

The Microsoft Graph PowerShell module is the preferred method for managing your Microsoft Cloud services through the command line. It provides a powerful, versatile, and feature-reach experience while allowing you granular control over your permissions.

Microsoft Graph PowerShell Module

The Microsoft Graph PowerShell Module is a set of PowerShell cmdlets that you can use to interact with Microsoft Graph. These cmdlets allow you to perform tasks such as querying data, creating and updating objects, and managing permissions.

In the post, I am going to explain why you should use the MS Graph PowerShell module and show you how to install MS Graph PowerShell.

Why use Microsoft Graph over the existing AzureAD and MSOnline PowerShell modules?

The Azure AD and MSOnline modules are set to be deprecated, likely around mid-2023. This has a few implications:

  1. You need to familiarize yourself with Microsoft Graph, as there are different commands compared to the existing modules.
  2. Existing scripts will need to be converted to work with Microsoft Graph.

Here are some of the things that you can do with the Microsoft Graph PowerShell Module.

  1. Query data from Microsoft 365 services.
  2. Create and update objects in Microsoft 365.
  3. Manage permissions in Microsoft 365.
  4. Automated tasks in Microsoft 365.

Prerequisites

Before proceeding with the installation, there are some essential prerequisites that need to be met:

  1. Ensure you have PowerShell 5.1 or a later version installed on your system.
  2. Verify that you have .NET Framework 4.7.2 or a more recent version installed.
  3. Install the latest version of PowerShellGet, essential for managing PowerShell modules.
  4. Adjust the PowerShell script execution policy to either "RemoteSigned" or a less restrictive policy.

How to Install Microsoft Graph PowerShell?

Step 1. Open PowerShell 7 with admin permission.

Install the Microsoft Graph PowerShell Module

Step 2. To install Microsoft Graph, you can run Install-Module Microsoft. Graph either for the current user context or for all users by using the -Scope parameter. By doing this, you will install the latest generally available (stable) version of the Microsoft Graph PowerShell module.

To install the module for the current user scope

  • Install-Module Microsoft.Graph -Scope CurrentUser.
    Install the Microsoft Graph PowerShell Module
  • Or to install for all users on your system: (you will need local admin rights on your system):
    Install the Microsoft Graph PowerShell Module

Install-Module Microsoft.Graph -Scope AllUsers

Step 3. You can confirm which version has been installed with the following command.

Get-InstalledModule | Where-Object {$_. Name -match "microsoft.graph"}

Your results should look like the following.

Install the Microsoft Graph PowerShell Module

Connect to Microsoft Graph with PowerShell

After installing the required module, you can use the Connect-MgGraph cmdlet to connect to your environment from within PowerShell.

However, when connecting to Microsoft Graph using the Connect-MgGraph cmdlet without any additional parameters, we will only have access to our user account within the PowerShell session. Therefore, it is essential to give the necessary permission scopes when establishing a connection to your environment.

If you want 'read' and 'write' access to all user accounts in your tenant:

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

Install the Microsoft Graph PowerShell Module

After successfully completing the authentication, you will be redirected to the web browser. Upon completion, you will obtain the following result.

Install the Microsoft Graph PowerShell Module

Install the Microsoft Graph PowerShell Module

Or, if you want 'read' and 'write' access to groups:

Connect-MgGraph -Scopes "Group.ReadWrite.All"

Install the Microsoft Graph PowerShell Module

Check out the reference sheet from Microsoft for installing PowerShell and permission.