How do I set up PowerShell modules correctly

I’m setting up PowerShell on a new machine and have been struggling to get the right modules installed or replaced to ensure this is a clean setup. For example, I’ve tried to update a module and I’m not able to because it says it wasn’t installed by module, so I must install another version of the same module instead of just upgrading the existing install. How can I remove the second installation or does it even matter?
This is what I get if I run the command “get-module -listavailable” and you can see two versions of the PnP.PowerShell, Microsoft.PowerApps.Administration, PowerShellGet

@IT_Matt99 Welcome to PowerShell.org forums.

If the module was installed using Install-Module, then its possible to uninstall using Uninstall-Module cmdlet. Other option is to remove the file from its source location.

$r = Get-Module -ListAvailable
$r | Select-Object -Property Name, Path

Will give path for each, you can manually remove the folder with the version number.

Hi @kvprasoon , Thanks You for your response, but if I run the uninstall-module, which version is going to be removed? I would like to keep the most up-to-date version and uninstall the old version.
Why does it keep adding versions instead of just updating the existing version?

It has a -RequiredVersion parameter.

OK, I don’t know PowerShell that well. So, what would the full command be to get rid of the older versions which are pictured in the graphic above?

the best way to get hands on it is using the examples in the help document
Get-Module (Microsoft.PowerShell.Core) - PowerShell | Microsoft Docs

@kvprasoon Since my objective has been to remove the multiple installation versions of the same module so would the command be

remove-module (microsoft.powershell.core) -PowerShell | Microsoft Doc

??

What I shared above is not eh command line, its the link to the help file. Please read, it will help you to get the exact solution.

1 Like