Uninstall Older Versions of a Installed PowerShell Module

When using Windows PowerShell, it's possible to use a PowerShell module. 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 = 'oh-my-posh';
$Latest = Get-InstalledModule $ModuleName;
Get-InstalledModule $ModuleName -AllVersions | ? {$_.Version -ne $Latest.Version} | Uninstall-Module -WhatIf