How to cleanup mess in modules and rescourceses

Welcome Forums General PowerShell Q&A How to cleanup mess in modules and rescourceses

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #59251

    Points: 0
    Rank: Member

    If I have had a good time playing around in Powershell, and got really big mess in installed modules and installed DSC rescourceses how can I clean everything up and get back to start? Start mening like my computer were newly installed ?

  • #59290

    Points: 527
    Helping Hand
    Rank: Major Contributor

    There isn't a way to 'reset' it per se, that I'm aware of. My first thought was to use Compare-Object against a "clean computer" for a baseline, but that's kind of dangerous because if you have features installed on one system and not the other (like RSAT\ActiveDirectory module) it could break things. The first question is where are you installing the modules? If you go to a prompt and type $env:PSModulePath, it will provide the directories that Powershell references when searching for Modules:

    PS C:\Users\Rob> $env:PSModulePath
    C:\Users\Rob\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\;C:\Users\Rob\Dropbox\Scrip

    Typical, "user installed" modules would most likely exist in the first path (C:\Users\Rob\Documents\WindowsPowerShell\Modules). This doesn't exist by default, so you could remove anything in there to reset modules. If you are installing "system" modules, those typically go into C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\. You can do into that directory and specifically delete modules you don't need, but that's where your "default" modules for the OS, Windows features, etc. are, so be careful. I don't see many modules installed in C:\Program Files\WindowsPowerShell\Modules, but you can check there as well. Of course, you have to do it with Powershell 🙂 :

    $modules = foreach ($module in Get-ChildItem ($env:PSModulePath -split ";")) {
        $module | Select Name, FullName, LastWriteTime, CreationTime
    $modules | Where{$_.Name -eq "PSDesiredStateConfiguration"} | Remove-Item -Recurse -Force

    The $modules should look like this:

    PS C:\Users\Rob> $modules
    Name                                      FullName                                                                              LastWriteTime          CreationTime      
    ----                                      --------                                                                              -------------          ------------      
    Microsoft.PowerShell.Operation.Validation C:\Program Files\WindowsPowerShell\Modules\Microsoft.PowerShell.Operation.Validation  7/16/2016 7:47:47 AM   7/16/2016 7:47:...
    PackageManagement                         C:\Program Files\WindowsPowerShell\Modules\PackageManagement                          7/16/2016 7:47:47 AM   7/16/2016 7:47:...
    Pester                                    C:\Program Files\WindowsPowerShell\Modules\Pester                                     8/16/2016 2:56:59 PM   7/16/2016 7:47:...
    PowerShellGet                             C:\Program Files\WindowsPowerShell\Modules\PowerShellGet                              7/16/2016 7:47:48 AM   7/16/2016 7:47:...
    PSReadline                                C:\Program Files\WindowsPowerShell\Modules\PSReadline                                 8/16/2016 2:56:59 PM   7/16/2016 7:47:...
    AppBackgroundTask                         C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\AppBackgroundTask                  10/24/2016 12:51:11 PM 7/16/2016 7:47:...
    Appx                                      C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Appx                               10/24/2016 12:51:11 PM 7/16/2016 7:47:...
    BitLocker                                 C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\BitLocker                          10/24/2016 12:51:12 PM 7/16/2016 7:47:...
    BitsTransfer                              C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\BitsTransfer                       10/24/2016 12:51:12 PM 7/16/2016 7:47:...
    CimCmdlets                                C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\CimCmdlets                         10/24/2016 12:51:13 PM 7/16/2016 7:47:...

    You could just datetime searches to see if you can find most of the newer stuff that you want to remove and just pipe it to Remove-Item. We'll see if anyone else has any insight.

The topic ‘How to cleanup mess in modules and rescourceses’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort