PowerTip: Unload All Non-Microsoft Modules

PowerTip: Unload All Non-Microsoft Modules

  • Comments 5
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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?

  • Jay, this may give a dice -
    Get-Module -ListAvailable | where Author -notmatch 'microsoft' | Remove-Module

  • 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.

  • Jay 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.

  • thanks