The Microsoft Graph module is a PowerShell module that provides cmdlets for managing the Microsoft 365 and Azure Active Directory resources through PowerShell.
Microsoft Graph API provides access to Microsoft 365 data and services such as users, groups, calendars, and files.
In this article, we will discuss how to install the Microsoft Graph PowerShell module.
The Microsoft Graph PowerShell SDK requires the following prerequisites:
- Upgrade to PowerShell 5.1 or later
- Install .NET Framework 4.7.2 or later
- Update PowerShellGet to the latest version using the
- The PowerShell script execution policy must be set to remote-signed or less restrictive. To set the execution policy, run the following command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Installing the Microsoft Graph Module in PowerShell
To install the Microsoft Graph v1.0 module in PowerShell Core or Windows PowerShell, run the following steps.
1. Open PowerShell Terminal
Launch PowerShell or PowerShell Core with administrator privileges. To do this, right-click on the PowerShell icon and select “Run as administrator“.
2. Install the Microsoft Graph PowerShell SDK
Run the following command in PowerShell to install the Graph module.
Install-Module Microsoft.Graph -Scope CurrentUser
This command fetches the module from the PowerShell Gallery and installs it on your system.
3. Accept the Untrusted Repository
Type Y to install the module from an untrusted repository and wait for the installation to complete.
How to Verify the Microsoft Graph Module in PowerShell Installed
To verify the Microsoft Graph module in PowerShell installed successfully, run the following command.
This command returns the installed version, name, and description of the Microsoft Graph module if it is installed on your system.
How to Import the Microsoft Graph Module in PowerShell
To import the Microsoft Graph module. Run the following command.
This command makes the Microsoft Graph module cmdlets available for use in your PowerShell session.
How to Connect to MgGraph in PowerShell
To connect to MgGraph with the scopes in PowerShell, run the following command.
Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All"
This command will prompt with the sign-in dialog box to authenticate the user.
If MFA is enabled, a verification code will be generated for your account. You will need to verify it using the authentical app that you have configured with your work or school account.
If you don’t have MFA enabled for your account, you can authenticate the user with a username and password.
Click on the Next button or Sign in to proceed further. It will ask you for permissions and consent on behalf of your organization for connecting to Microsoft Graph PowerShell.
Enabled the checkbox “Consent on behalf of your organization” and click the Accept button.
After the successful verification, it will return to the PowerShell terminal and display the welcome message as given below.
PS C:\> Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All" Welcome to Microsoft Graph! Connected via delegated access using 14d82eec-204b-4c2f-b7e8-296a70dab67e Readme: https://aka.ms/graph/sdk/powershell SDK Docs: https://aka.ms/graph/sdk/powershell/docs API Docs: https://aka.ms/graph/docs NOTE: You can use the -NoWelcome parameter to suppress this message.
You can now use the Microsoft Graph API to manage the Microsoft 365 data and services such as users, groups, etc…
You can use the Get-MgUser cmdlet in the Microsoft Graph module to get the users available in Microsoft 365.
This command gets a list of all the users.
How to Update the Microsoft Graph PowerShell Module
To update the Microsoft Graph module in PowerShell to get the latest features, run the following command.
This command will update the Microsoft Graph SDK and all of its dependencies.
How to Uninstall the Microsoft Graph PowerShell Module
To uninstall the Microsoft Graph module in PowerShell, run the following command to uninstall the main module.
Uninstall-Module Microsoft.Graph -AllVersions
This command will remove the main module.
Then, remove all of the dependency modules by running the following commands.
Get-InstalledModule Microsoft.Graph.* | ? Name -ne "Microsoft.Graph.Authentication" | Uninstall-Module Uninstall-Module Microsoft.Graph.Authentication
I hope the above article on how to install the Microsoft Graph PowerShell module is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.