Run the following commands to verify the NuGet provider is installed:

Find-PackageProvider -Name NuGet -Force -ForceBootstrap

Run the following commands to define the name of the PowerShell module and any prerequisite modules:

$Name = 'Microsoft.Graph'
$PrerequisiteModuleNames = 'Microsoft.Graph.Authentication'

Run the following commands to define the Azure PowerShell modules respecting the dependency on the Microsoft.Graph.Authentication module:

$Modules, $PrerequisiteModules = (Get-Module -Name "$Name.*").Where({$_.Name -notin $PrerequisiteModuleNames},[System.Management.Automation.WhereOperatorSelectionMode]::Split)

Run the following commands to unload the Azure PowerShell modules respecting the dependency on the Az.Accounts module:

$Modules | ForEach-Object { Remove-Module -Name $_.Name -Force }; $PrerequisiteModules | ForEach-Object { Remove-Module -Name $_.Name -Force }

Run the code blocks in one of the following sections to update or install the latest version of the Azure PowerShell modules from the PSGallery: