PowerTip: Unload All Non-Microsoft Modules

Summary: Learn to unload all non-Microsoft Windows PowerShell modules.

Hey, Scripting Guy! Question Windows PowerShell is acting funny and I want to unload all modules that are not written by Microsoft.
          How can I easily do this?

Hey, Scripting Guy! Answer Use Get-Module to find all loaded modules, use the Where-Object cmdlet to filter for authors
          that do not match Microsoft, and then pipe the results to the Remove-Module cmdlet:

Get-Module | where Author -notmatch 'microsoft' | Remove-Module

Comments (5)

  1. Chen V says:

    Jay, this may give a dice –
    Get-Module -ListAvailable | where Author -notmatch ‘microsoft’ | Remove-Module

  2. Chen V says:

    After removing if you run Get-Command -ModuleName – it will show the result because it exists in the RunSpace.

    If you close and reopen the console you don’t get it.

  3. Greg Wojan says:

    [mention:48a71416ddcd474cac5d85994f0265ca:ca0e7c8086864d2fa5a863b9e212e922] The problem you’re having is the command ‘get-command -ModuleName CiscoUcsPS’ forces the module to be reloaded. If you simply do ‘get-module CiscoUcsPS’ it will return nothing
    if it’s not currently loaded. You can also tell PowerShell not to implicitly load modules but that can be infuriating when you’ve come to rely on it.

  4. jay says:

    This was exactly what I needed today! Except after I run the command I still have the non-microsoft commands from the module I just removed. when I run get-command -ModuleName CiscoUcsPS they are all still there. Any thoughts?