Assistance at your fingertips...

PowerShell Module Bloat

Module bloat is a real problem. We still haven’t decided, me and my engineering friends, the best way to approach the problem. When you have even just 3 GB of Modules, having that repeated even ONCE is a serious issue. Here is a probable solution. *Set a single Modules folder to be your Modules path and ensure you use version subfolders.

PLEASE GOD, Microsoft, USE STANDARDS in your PowerShell module development to require version subfolders FROM NOW ON for ANY PowerShell Module updates, so we can all use Hybrid ‘side-loading’paths on Domain Controllers?
Pretty please with sugar on top?!*

*Erase the Env:PSModulesPath entirely:

$env:PSModulePath = ''

And replace with the path all Modules are in:

$env:PSModulePath = 'D:\PowerShell\Modules'

In this manner you control the Modules folder size, and also ensure your don’t have 8 different Modules directories to deal with in PWSH

*FAIR WARNING: ONLY once you confirm this single Modules folder path works should you add those two lines to your $profile for both Powershell/ISE and PWSH

$env:PSModulePath = ''
$env:PSModulePath = 'D:\PowerShell\Modules'

Testing: Before making permanent changes, test the new setup in a temporary session to gauge any impacts on your workflow. You can always close and re-open to reset, then. I mean, the safest method is to make a PS script to set the $Env:PSModulesPath, at-will, right?

Permanent: To make this change permanent, for future PowerShell, ISE and PWSH sessions, add the following lines to your $profile script:

$env:PSModulePath = ''
$env:PSModulePath = 'D:\PowerShell\Modules'

If the modules folder in your PowerShell environment becomes too large, resulting in slow or halted PowerShell Intellisense features, there are the most common strategies you can employ to optimize PS performance:

  1. Clear all cached modules and only load modules you need:
    Remove Unnecessary Modules: Remove-Modules * -force -verb
  2. Remove unneeded modules with Uninstall-module
  3. Consolidate all module into one folder (We recommend Beyond Compare for that using synch folder) *BE CAREFUL. MAKE BACKUPS*

*THE DOWNSIDE: Just know you run the risk of completely hosing PowerShell to remove ALL your cached modules. Ask me how I know… 😉
And it will be FAR worse if you don’t backup, test thoroughly on a test system, FIRST.

* I cannot be, will not be, responsible for you not following instructions, -Patrick Burwell 01/01/1996, in perpetuity.

*Microsoft would need to standardize ALL PowerShell and PWSH development to use Versioned Sub-Folders


Posted

in

, , ,

by