Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Run

...

the following

...

commands to

...

This will perform the following actions for each PowerShell module:

...

verify the NuGet provider is installed:

Code Block
languagepowershell
Find-PackageProvider -Name 'NuGet' -Force -ForceBootstrap

Run the following commands to trust the PSGallery:

Code Block
languagepowershell
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted

Run the following commands to define the names of the Graph PowerShell module collection and of any modules that are a dependency for other modules the collection:

Code Block
languagepowershell
ForEach ($ModuleName in $PSModuleName) { 
$Name = @{ Name = $ModuleName; ErrorAction = [System.Management.Automation.ActionPreference]::Stop}; 
$Confirm = @{ Confirm = $false }; 
$PowerShellModuleName = 'Microsoft.Graph'
$DependsOnModuleNames = 'Microsoft.Graph.Authentication'

Run the following commands to split the Graph PowerShell modules based upon the module dependencies:

Code Block
languagepowershell
$Modules, $Dependencies = (Get-Module -ListAvailable | Where-Object { Name "$PowerShellModuleName.*").Where({$_.Name -innotin $PSModuleName }$DependsOnModuleNames},[System.Management.Automation.WhereOperatorSelectionMode]::Split)

Run the following commands to unload the Graph PowerShell modules respecting the module dependencies:

Code Block
languagepowershell
$Modules | RemoveForEach-Module @Confirm; 
Try { 
	Update-Module @Name @Confirm
} 
Catch { 
Try { 
	InstallObject { Remove-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 $_.Name -Force }; $Dependencies | ForEach-Object { Remove-Module -Name $_.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
}

Force }

Run the following commands to remove the Graph PowerShell modules currently installed:

Code Block
Get-ChildItem -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Filter "$PowerShellModuleName*" | Remove-Item -Force -Recurse

Run the following commands to install the latest version of the Graph PowerShell modules from the PSGallery: 

Code Block
languagepowershell
Save-Module -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Name $PowerShellModuleName -Force