HOW TO uninstall older versions of a PowerShell module installed

When using Windows PowerShell ISE it’s possible to import a PowerShell module, open the Command tool panel (from the menu Add-ons -> Command) and clicking Refresh, then have a list of the commands available.

It’s annoying that sometimes the same command appears multiple times, as the result of an installed PowerShell module that you updated.

Today’s example is from NavContainerHelper PowerShell module, searching in my pc for one of its commands I had multiple entries for the same command, as shown in the following picture:

Solution:
Run Windows PowerShell ISE as Administrator.
Copy and paste the following PowerShell script that retrieves the latest version of the desired module and then recursively uninstalls the previous versions installed.
Interesting to note, you can use the -WhatIf parameter at the end to simulate and preview the changes without doing them (remember to remove -WhatIf parameter when you want to apply the changes and to set the $ModuleName to the desired PowerShell module).

$ModuleName = 'navcontainerhelper';
$Latest = Get-InstalledModule $ModuleName; 
Get-InstalledModule $ModuleName -AllVersions | ? {$_.Version -ne $Latest.Version} | Uninstall-Module -WhatIf

To see the command list updated you need to restart Windows PowerShell ISE.

Did my HOW TO help you? Leave a reply.

DevOps Deployment Group script stuck on “Connecting to the server.”

Scenario:
I’m adding a machine to a Deployment Group in DevOps, I copied the script from DevOps page and pasted in Windows PowerShell ISE that I’m running as Administrator in the target machine.

Run the script, it starts showing the steps until it stops (no errors shown) at the step

Connecting to the server.

Solution:
Run the script using Windows PowerShell (Run as Administrator) rather than using Windows PowerShell ISE

Did my solution solve your problem? Leave a reply.