Cleaning Up PowerShell Modules (Part 1)

by Jun 29, 2022

There are plenty of scripts available that promise to read the original Windows 10 product key from the registry by converting a series of binary values.

In the first part of this mini-series, we’ll check out where PowerShell keeps its modules, and what you can do to get rid of modules you no longer require.

The safest approach is to focus entirely on modules that were installed via “Install-Module” because that way you can never accidentally delete a module that was part of Windows or another software product.

This one-liner lists all modules that were installed by Install-Module and lets you select the ones you want to (permanently) remove.

Get-InstalledModule | 
  Out-GridView -Title 'Select module(s) to permanently delete' -PassThru |
  Out-GridView -Title 'Do you REALLY want to remove the modules below? CTRL+A and OK to confirm' -PassThru |
  Uninstall-Module

Note: you may need Administrator privileges if the module was installed in “AllUsers” scope.

Attention: when you remove a module, it will be permanently deleted from your hard drive. Make sure you know which cmdlets it shipped, and that you do not require them any longer. If you accidentally deleted a module, you can always reinstall it via Install-Module.


Twitter This Tip! ReTweet this Tip!