The Microsoft Graph PowerShell module is a handy tool that provides a set of cmdlets to interact with Microsoft’s powerful Graph API directly from PowerShell. This enables users to automate and manage resources across a variety of Microsoft services like Office 365, Azure Active Directory, and more.
I am going to show you how to install the module quickly and get access to it.
Install-Module Microsoft.Graph -Scope CurrentUser
To install the beta module, execute the following command:
Install-Module Microsoft.Graph.Beta -Scope CurrentUser
Once the installation is done, you can check the version with this command.
Get-InstalledModule Microsoft.Graph
Get-InstalledModule Microsoft.Graph.Beta
If you have already installed a version of the Microsoft Graph and would like to update it to the latest version, please update the version to the latest with this command.
Update-Module Microsoft.Graph
If you would like to uninstall the Microsoft Graph and dependencies with the module, execute the following command.
Uninstall-Module Microsoft.Graph -AllVersions
Get-InstalledModule Microsoft.Graph.* | ? Name -ne "Microsoft.Graph.Authentication" | Uninstall-Module -AllVersions
Uninstall-Module Microsoft.Graph.Authentication -AllVersions
Basically two options available to connect to Microsoft Graph;
- Delegated (User name and Password, classic method)
- Application (Without sign-in with user name and credentials)
Delegated
To sign in with the necessary scopes, use the Connect-MgGraph command. You’ll need to use an admin account to give permission for the required scopes.
Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All"
The command will take you to a web page where you can sign in using your credentials. Once you’ve done that, the command will show you a message saying Welcome To Microsoft Graph! You only need to sign in once per session.
you can also use app permissions to grant direct access to the application, which does not require a user to be signed in. These permissions are often used for background services or daemon apps that need full access.