Removing a PowerShell module using its version number


Is there an easy way to pass version as a parameter to Get-Module?

I have two different versions of Azure PowerShell installed:

And I wish to remove one of them using a command like:


Please see: get-help Remove-Module -full


FullyQualifiedName parameter accepts a module name that is specified in the format @{ModuleName = “modulename”; ModuleVersion = “version_number”}

Based on that, the following should be what you are after:

Improved Answer (edit)

Did more investigation on this, and there are some quirks when removing using ModuleVersion (which can be a string or a [version]).

If you specify ModuleVersion, Remove-Module will remove all matching modules with that version and greater.

To get an explicit match, you must also pass the guid.

Since that is a lot to type, I suggest adding a function to your profile to make this easier.

and call like:

Testing and analysis

I might as well share how I tested this to arrive at my conclusion. I will leave some details to the reader for self-investigation…

Create two modules, and export a function from each, using different function names to make testing easier.

D:\test\modtest\v1\ModTest.psd1 with version

D:\test\modtest\v2\ModTest.psd1 with version

Create a function to load the modules, call exported functions, show modules before, remove a module using the parameters specified, show modules after.

call various ways to demonstrate how Remove-Module works…

This is the part, where I leave it to the reader to analyze the output further to verify the conclusions of this article.

That said, this was what I noticed that caused me to investigate further:

Notice that when removing, it works as expected. When removing, both and are removed!


Removing a PowerShell module using its version number by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply