Run one of the following code blocks to install the latest version of the Microsoft Graph PowerShell modules from the PSGallery:
This will perform the following actions for each PowerShell module:
- Remove the module from the current session if loaded
- Update the module if installed and install the module if not
- Uninstall any previous versions of the module
ForEach ($ModuleName in $PSModuleName) {
$Name = @{ Name = $ModuleName; ErrorAction = [System.Management.Automation.ActionPreference]::Stop};
$Confirm = @{ Confirm = $false };
Get-Module -ListAvailable | Where-Object { $_.Name -in $PSModuleName } | Remove-Module @Confirm;
Try {
Update-Module @Name @Confirm
}
Catch {
Try {
Install-Module @Name -AcceptLicense @Confirm} Catch { Install-Module @Name @Confirm }
}
$Module = Get-InstalledModule @Name; Get-InstalledModule @Name -AllVersions | Where-Object { $_.Version -lt $Module.Version } |
Uninstall-Module @Confirm }
####
$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
}