Uninstall previous versions of PowerShell module
Prerequisites
The PowerShellModuleName variable must already be defined or one of the following values must be set:
Run the following commands to retrieve the latest version of the PowerShell module in PSGallery:
$ModuleInGallery = Find-Module -Name $PowerShellModuleNameRun the following commands to retrieve the versions of the PowerShell module on the local system:
$ModulesOnSystem = Get-Module -ListAvailable -Name $PowerShellModuleNameRun the following commands to review the previous versions of the PowerShell module on the local system:
$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:
$ModulesOnSystem | ForEach-Object { If ($_.Version -lt $ModuleInGallery.Version) { $_ | Uninstall-Module } }