Prerequisites
The PowerShellModuleName variable must already be defined or one of the following values must be set:
Expand |
---|
title | Common PowerShell module names |
---|
|
Code Block |
---|
| $PowerShellModuleName = 'ExchangeOnlineManagement' |
|
Run the following commands to retrieve the latest version of the PowerShell module in PSGallery:
Code Block |
---|
|
$ModuleInGallery = Find-Module -Name $PowerShellModuleName |
Run the following commands to remove any previous retrieve the versions of installed PowerShell modulesthe PowerShell module on the local system:
Code Block |
---|
|
$InstalledModules$ModulesOnSystem = Get-InstalledModule; ForEach ($Module in $InstalledModules) { Get-InstalledModule -Name $Module.Name -AllVersions | WhereModule -ListAvailable -Name $PowerShellModuleName |
Run the following commands to review the previous versions of the PowerShell module on the local system:
Code Block |
---|
|
$ModulesOnSystem | ForEach-Object { If ($_.Version -lt $ModuleInGallery.Version) { $_ } } |
Run the following commands to remove the previous versions of the PowerShell module on the local system:
Code Block |
---|
|
$ModulesOnSystem | ForEach-Object { If ($_.Version -nelt $Module$ModuleInGallery.Version) }{ $_ | Uninstall-Module } } |