Installing/Upgrading Microsoft Graph Modules

Microsoft Graph API is a powerful and comprehensive service provided by Microsoft that allows developers to access a wide range of data and resources across Microsoft 365 and other Microsoft services. It enables developers to build powerful applications that leverage the data and intelligence from various Microsoft services, including Office 365, OneDrive, Azure Active Directory, and more. The API offers a unified and consistent way to interact with these services, allowing developers to create custom solutions that integrate with Microsoft's ecosystem. With Microsoft Graph API, developers can access user data, manage files, create and manage groups, and perform various administrative tasks, among many other capabilities.

PowerScripts can take advantage of the Microsoft Graph modules and most of our native scripts will move towards Microsoft Graph as older PowerShell modules are sunset by Microsoft.

There are two things that you must do to use Microsoft Graph in your script:

  1. Specify the modules you intend to use in the script, by selecting them from the drop-down list of available modules, as shown below:

2. The graph modules must be installed on the machine hosting PowerScripts.

Installing Microsoft Graph the first time

Open PowerShell as an administrator.

Install the Microsoft.Graph PowerShell module by typing the following command:

Install-Module Microsoft.Graph

If prompted to install from an untrusted repository, type Y and hit enter to continue.

Wait for the installation to complete. All the modules will take 10 minutes or more to install.

Alternatively, you can install individual modules with commands such as:

Install-Module Microsoft.Graph.Authentication

But this will soon grow wearisome because there are over 25 modules as of this writing.

Once the installation is complete, you can use the module in PowerScripts by selecting it from the modules list. You don’t have to include an import-module statement in your script, PowerScripts will import the module automatically.

That's it! You should now be able to use the Microsoft Graph PowerShell modules.

Upgrading Microsoft Graph Modules

You can install updated modules as they are released, but in our experience this soon gets messy as you will have multiple versions of the same module on the machine which will make troubleshooting all the more difficult. The cleanest way to upgrade is to remove the existing modules then run install-module microsoft-graph again.

Here is a PowerShell script which will remove your existing Microsoft Graph modules:

$Modules = Get-Module Microsoft.Graph* -ListAvailable | Where {$_.Name -ne "Microsoft.Graph.Authentication"} | Select-Object Name -Unique
Foreach ($Module in $Modules)
{
$ModuleName = $Module.Name
$Versions = Get-Module $ModuleName -ListAvailable
Foreach ($Version in $Versions)
{
$ModuleVersion = $Version.Version
Write-Host "Uninstall-Module $ModuleName $ModuleVersion"
Uninstall-Module $ModuleName -RequiredVersion $ModuleVersion
}
}
#Uninstall Microsoft.Graph.Authentication
$ModuleName = "Microsoft.Graph.Authentication"
$Versions = Get-Module $ModuleName -ListAvailable
Foreach ($Version in $Versions)
{
$ModuleVersion = $Version.Version
Write-Host "Uninstall-Module $ModuleName $ModuleVersion"
Uninstall-Module $ModuleName -RequiredVersion $ModuleVersion
}