Question: The system appears to have two (2) versions of PowerShellGet module installed.

```
Script     2.2        PowerShellGet
Script     1.0.0.1    PowerShellGet

```

How can I uninstall the older version? The `Uninstall-Module` command appears to be looking in the `2.2` directory. Why is that?

```
>Uninstall-Module -Name 'PowerShellGet' -RequiredVersion '1.0.0.1'
PackageManagement\Uninstall-Package : No match was found for the specified search criteria and module names 'PowerShellGet'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:12655 char:21
+ ...        $null = PackageManagement\Uninstall-Package @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

```

When I try to specify the older version, it reports the new version.

```
>Get-Module -FullyQualifiedName @{ModuleName="PowerShellGet";ModuleVersion="1.0.0.1"}

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.2        PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

>($PSVersionTable.PSVersion).ToString()
5.1.14409.1018
>(Get-CimInstance -ClassName Win32_OperatingSystem).Caption
Microsoft Windows 7 Enterprise

```

Answer: 
**Short answer:**

You can't that uninstall something with `PowerShellGet` if it wasn't installed with `PowerShellGet`.

**Long answer:**

`PowerShellGet v1.0.0.1` was installed as a part of Windows, and not using `PowerShellGet` (naturally). Hence, why you can't use `PowerShellGet` to `Uninstall-Module` it.

`PowerShellGet v2.2` on the other hand, *is* installed with `PowerShellGet` and so you *can* `Uninstall-Module` it. You can also update it etc.

If you really want to uninstall the v1.0.0.1 version, you have to follow these
[Steps](http://shaulov.us/2018/01/13/upgrading-powershellget-1-0-0-1-to-the-latest-version/):

> 
> 1. Browse to `C:\Program Files\WindowsPowerShell\Modules\`
> 2. Go into `C:\Program Files\WindowsPowerShell\Modules\PowershellGet` folder, and delete the sub- folder `1.0.0.1`
> 3. Then do the same for `C:\Program Files\WindowsPowerShell\Modules\PackageManagement`, delete the
>  sub-folder `1.0.0.1`
> 
> 
>
There seems to be a special situation with PowerShellGet.

However in general, i use this script here:

```
$ModuleName = 'YourModuleName';
$Latest = Get-InstalledModule $ModuleName; 
Get-InstalledModule $ModuleName -AllVersions | Sort-Object -Descending {[Version]$_.Version} | Select-Object -Skip 1 | Uninstall-Module -WhatIf

```

Remember to remove the "-WhatIf" tag once you're happy with the result.

Credits to Eclipses:
<https://www.myerrorsandmysolutions.com/how-to-uninstall-older-versions-of-a-powershell-module-installed/>