Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Download and Install Microsoft Graph Module in PowerShell

October 20, 2023
in Blog, Microsoft Graph
0
ADVERTISEMENT

Table of Contents

Microsoft Graph PowerShell replaces the Entra ID PowerShell and MSOnline modules. Therefore, we suggest you to use MS Graph PowerShell SDK to connect with Entra ID. In this article, you will learn how to install Microsoft Graph PowerShell module.

Prerequisites Microsoft Graph PowerShell

Before you can install Microsoft Graph PowerShell module, you need to set up the system. The following prerequisites are required to use the Microsoft Graph PowerShell SDK with Windows PowerShell:

  • Upgrade to PowerShell 5.1 or later.
  • Install .NET Framework 4.7.2 or later.

However, there are no additional prerequisites to use the Microsoft Graph PowerShell SDK if you install PowerShell 7 on Windows. Therefore, it is recommended to use PowerShell 7 or later with Microsoft Graph PowerShell SDK on all platforms.

Install Microsoft Graph PowerShell SDK

The Microsoft Graph PowerShell SDK consist of two modules. Follow the below steps to install Microsoft Graph module and Microsoft Graph Beta module on PowerShell.

Note Note: You need install Microsoft Graph modules only once. In the next time, run Connect-MgGraph to connect to Microsoft Graph.

1️⃣ Right click on the Windows Start icon then select Windows PowerShell Admin (On Windows 11, select Terminal Admin).

Pw3

2️⃣ Copy then run all below commands at once:

Note Note: It may take a couple of minutes to download and install the Microsoft Graph module.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
Install-PackageProvider -Name NuGet -Force
Install-Module PowerShellGet -Force
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module Microsoft.Graph -Force
Install-Module Microsoft.Graph.Beta -AllowClobber -Force

Installation commands explanation:

  • By default, we can’t install scripts. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, you need to Set-ExecutionPolicy.
  • Install NuGet provider.
  • Install PowerShellGet module.
  • Install Microsoft Graph module. Install the Microsoft Graph Beta module. Add the parameters -AllowClobber and -Force to prevent conflicts when upgrading from other module versions. This may be the case when upgrading from v1.x to v2.x.

3️⃣ Verify you installed the Microsoft Graph module. Use the below PowerShell cmdlet to check Microsoft Graph PowerShell module version.

Get-InstalledModule | ? {($_.Name -eq 'Microsoft.Graph') -or ($_.Name -eq 'Microsoft.Graph.Beta')}

Version Name                 Repository Description
------- ----                 ---------- -----------
2.6.1   Microsoft.Graph      PSGallery  Microsoft Graph PowerShell module
2.6.1   Microsoft.Graph.Beta PSGallery  Microsoft Graph PowerShell module

Alternatively, we’ve created a PowerShell script to install all Microsoft 365 PowerShell modules automatically. You can install using a simple command:

irm bonguides.com/pw | iex
1ysZFOfBW9NeT1xqVQwclqVV2IW024785yfwAbG7z193vBSGW3iNEKU7zGY7

Connect to Microsoft Graph PowerShell

You can connect to Microsoft Graph PowerShell with or without MFA. For this example, we will show you how to connect with interactive mode.

1️⃣ Run the PowerShell cmdlet with the below scopes.

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

2️⃣ The sign-in window opens.

  • Enter your admin account and password.
  • Click Sign in.
bgfQhYACkpx9lnO7Isr7VMXrFbySu7pbAiL9tFTeCqXgj3cDtzlaMDJlJ4MC

If you have MFA enabled, you will get a verification code sent as a text message or to your Authentication app on your phone. If your MFA is disabled, you will not do anything here.

3️⃣ It shows the permissions you allow Microsoft Graph to use.

  • Select Consent on behalf of your organization
  • Click Accept
ZIxLy6vC0579btU6owAmxCvppNJqDhlKWLHlOo3pyFtmDu7NGilijX6QQOww

4️⃣ After the verification, you can go back to your PowerShell window.

PS C:\> Connect-MgGraph -Scopes "User.ReadWrite.All","Group.ReadWrite.All"
Welcome To Microsoft Graph!

Read more: There are other methods to Connect to Microsoft Graph PowerShell without authentication, like self-signed certificate or client secret.

  • Connect to Microsoft Graph PowerShell with client secret.
  • Conect to Microsoft Graph PowerShell using certificate.

5️⃣ To verify you connected with the correct permissions, use Get-MgUser cmdlet. Or you can use the Get-MgContext cmdlet to get more details about the current session.

PS C:\> Get-MgUser -All | select DisplayName, UserPrincipalName

DisplayName               UserPrincipalName
-----------               -----------------
Conf Room Adams           [email protected]
Adele Vance               [email protected]
MOD Administrator         [email protected]
Alex Wilber               [email protected]
...
PS C:\> Get-MgContext

ClientId              : 14d82eec-204b-4c2f-b7e8-296a70dab67e
TenantId              : c032627b-6715-4e39-9990-bcf48ee5e0c5
CertificateThumbprint :
Scopes                : {Application.ReadWrite.All, Directory.Read.All, openid...}
AuthType              : Delegated
AuthProviderType      : InteractiveAuthenticationProvider
CertificateName       :
Account               : [email protected]
AppName               : Microsoft Graph Command Line Tools
ContextScope          : CurrentUser
Certificate           :
PSHostVersion         : 5.1.22621.1778

Run the below cmdlet to use the Microsoft Graph Beta.

Get-MgBetaUser -All

Disconnect Microsoft Graph PowerShell

Always disconnect the remote PowerShell session when you finish, to avoid waiting for older sessions to expire. Disconnect the remote PowerShell session once you finish with the below cmdlet.

PS C:\> Disconnect-MgGraph

ClientId               : 14d82eec-204b-4c2f-b7e8-296a70dab67e
TenantId               : c032627b-6715-4e39-9990-bcf48ee5e0c5
Scopes                 : {Group.ReadWrite.All, openid, profile, User.ReadWrite.All...}
AuthType               : Delegated
TokenCredentialType    : InteractiveBrowser
CertificateThumbprint  :
CertificateSubjectName :
Account                : [email protected]
AppName                : Microsoft Graph Command Line Tools
ContextScope           : CurrentUser
Certificate            :
PSHostVersion          : 5.1.19041.3031
ManagedIdentityId      :
ClientSecret           :
Environment            : Global

You can check you disconnected correctly, if you run the above cmdlet again. The below output shows there is no application to sign out from, because you already disconnected Microsoft Graph.

PS C:\> Disconnect-MgGraph
Disconnect-MgGraph : No application to sign out from.
At line:1 char:1
+ Disconnect-MgGraph
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Disconnect-MgGraph], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.DisconnectMgGraph

Uninstall Microsoft Graph PowerShell module

To uninstall all the Microsoft Graph PowerShell modules, including the beta version, run the below commands.

Note Note: You need to run all the commands below to completely remove Microsoft Graph from the system. It can take around 15 minutes for the uninstallation to complete. Wait and don’t close the PowerShell session.
Uninstall-Module Microsoft.Graph -AllowPrerelease -AllVersions
Uninstall-Module Microsoft.Graph.Beta -AllowPrerelease -AllVersions
Get-InstalledModule Microsoft.Graph.* | ForEach-Object{
    if($_.Name -ne "Microsoft.Graph.Authentication"){ 
        Uninstall-Module $_.Name -AllowPrerelease -AllVersions 
    } 
}
Uninstall-Module Microsoft.Graph.Authentication -AllowPrerelease -AllVersions

You can get the error: No match was found. The error looks like the example shown below, but it is not a problem. It means that the specified Microsoft Graph module is already removed. Proceed with the other commands.

PackageManagement\Uninstall-Package : No match was found for the specified search criteria and module names 'Microsoft.Graph'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:12733 char:21
+ ...        $null = PackageManagement\Uninstall-Package @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

Finding Microsoft Graph Scopes

Note Related: How to Determine What Microsoft Graph Permissions You Need to Connect

Finding the right scope can be a bit challenging at the beginning. But there are two good sources that you can use to determine which scopes you will need to specify:

  • Microsoft Graph Explorer: https://developer.microsoft.com/en-us/graph/graph-explorer
  • Microsoft Graph Rest API Reference: https://docs.microsoft.com/en-us/graph/api/overview

Microsoft Graph Explorer

The Microsoft Graph Explorer is a great tool to test out API calls to Microsoft Graph. It comes with a lot of examples calls to help you get started. But it will also list the required permission for the call.

Open the Graph Explorer | Select an Sample Query on the left side | Click Modify Permissions tab.

Bg1266

Microsoft Graph Rest API Reference

The other option is to use the Rest API Reference. You can select in the left menu one of the entities that you want to work with and then view the required permissions. You don’t need to add all scope, they are listed from least to most privileged.

An example, we find the scope to get OneDrive for Business for users.

Bg1267

Frequently Asked Questions (FAQ)

How to run Microsoft Graph PowerShell as administrator?

Click on Start and search for the PowerShell app. On the right side, click on Run as administrator. Or you can right-click the PowerShell icon and select Run as administrator. This way, you can run PowerShell commands without restrictions.

Why do I need to install Microsoft Graph PowerShell?

Installing Microsoft Graph PowerShell provides access to Entra ID and MSOnline modules. Since Azure Active Directory Graph is deprecated, it’s required to install Microsoft Graph PowerShell. Microsoft Graph is also more secure and resilient than Entra ID Graph.

Multi-factor authentication (MFA) when I connect to Microsoft Graph PowerShell?

To connect to Microsoft Graph PowerShell, you don’t need MFA enabled. The cmdlet Connect-MgGraph works for accounts with or without MFA. However, we recommend enabling MFA to protect your organization and have strong security.

Which Microsoft Graph PowerShell module do I need to install?

It’s best to install the necessary modules including Microsoft.Graph.Authentication which is installed by default. If you using an older MS Graph module, you should update it to the latest module using the cmdlet Update-Module Microsoft.Graph.

Do I need to install the Microsoft Graph Beta module?

We recommend installing the Microsoft.Graph.Beta module to use commands that are not yet available in the Microsoft Graph module v2.x. Otherwise, you can’t run these commands and you will get the error: No match was found.

Conclusion

You learned how to install Microsoft Graph PowerShell module and update to the latest version. It is recommended to install the Microsoft Graph Beta module to use the cmdlets that are not yet available in the latest version v2. Connect to Microsoft Graph PowerShell with or without MFA to use the new cmdlets. Always remember to disconnect when you finish.

Not a reader? Watch this related video tutorial:

5/5 - (4 votes)
Previous Post

How to Download and Install Visio 2021 with Office 365 on Same Machine

Next Post

How To Connect To Microsoft Graph API Using PowerShell

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory