title: Powershell won't install almost any module using install-module
body: <p>My Powershell v5.1 won't install almost any module automatically using <code>install-module</code> whereas manually installation does work.</p>
  
  <p>First, when I run <code>install-module</code>, it would download the module then throw an error, say the pscx module: </p>
  
  <pre><code>PackageManagement\Install-Package : Package 'Pscx' failed to be installed because: Specified cast is not valid.
  At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:9307 char:21
  + ...          $null = PackageManagement\Install-Package @PSBoundParameters
  +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidResult: (Pscx:String) [Install-Package], Exception
      + FullyQualifiedErrorId : Package '{0}' failed to be installed because: {1},Microsoft.PowerShell.PackageManag
     ement.Cmdlets.InstallPackage
  </code></pre>
  
  <p>What I can do now is to manually download the module and use <code>import-module</code> myself. The error occurs almost every time when I'm trying to install any module through this cmdlet. How can I address this problem?</p>
  
  <p>For troubleshooting, <code>Get-PSRepository</code> gives me this:</p>
  
  <pre><code>PS C:\&gt; Get-PSRepository
  
  Name                      InstallationPolicy   SourceLocation
  ----                      ------------------   --------------
  PSGallery                 Trusted              https://www.powershellgallery.com/api/v2
  GalleryRolling            Trusted              https://www.poshtestgallery.com/api/v2/
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Got the same error when trying to use <code>Save-Module</code>:</p>
  
  <pre><code>PS C:\&gt; Find-Module -Name 'pscx' | Save-Module -Path "G:\Temp\System Documents\WindowsPowerShell\Modules"
  WARNING: Package 'Pscx' failed to be installed because: Specified cast is not valid.
  WARNING: Package 'Pscx' failed to install.
  PackageManagement\Save-Package : Unable to save the module 'Pscx'.
  At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:11331 char:25
  + ...             $null = PackageManagement\Save-Package @PSBoundParameters
  +                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (Microsoft.Power...ets.SavePackage:SavePackage) [Save-Packag
     e], Exception
      + FullyQualifiedErrorId : ProviderFailToDownloadFile,Microsoft.PowerShell.PackageManagement.Cmdlets.Save
     Package
  </code></pre>
  
  <p>It downloaded the package then displays the <code>WARNING</code>.</p>
  
  <p>When using the <code>Find-Module</code> alone, the result is:</p>
  
  <pre><code>PS C:\&gt; Find-Module -Name 'pscx'
  
  Version              Name                                Repository           Description
  -------              ----                                ----------           -----------
  3.3.2                Pscx                                PSGallery            PowerShell Community Extensi...
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 2:</strong>  </p>
  
  <p>Oh I forgot to say that there are no files created in the specific download folder after the download process bar disappeared. Does that mean the download has failed?</p>
  
  <hr>
  
  <p><strong>EDIT 3:</strong> @Sage Pourpre</p>
  
  <ol>
  <li><a href="https://1drv.ms/t/s!AlWbFX-I-J_1jRKBmnliw6UWDNIb" rel="noreferrer">Debugging log</a>  </li>
  <li>I Always run PS as administrator.</li>
  <li><code>-Scope CurrentUser</code> throws the same error.</li>
  <li><p>Both <code>PS C:\&gt; Uninstall-Module -Name "PowerShellGet"</code> and <code>PS C:\&gt; Uninstall-Script -Name "PowerShellGet" -RequiredVersion 2.0.3</code> produce the same result.</p>
  
  <p>PackageManagement\Uninstall-Package : No match was found for the specified search criteria and script names
  'PowerShellGet'.
  At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:12343 char:21</p>
  
  <ul>
  <li>...        $null = PackageManagement\Uninstall-Package @PSBoundParameters</li>
  <li><pre><code>+ CategoryInfo          : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstal
  l-Package], Exception
  + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
  </code></pre></li>
  </ul></li>
  </ol>
  
  <p>Then I tried to list available modules:</p>
  
  <pre><code>PS C:\&gt; Get-Module -ListAvailable
  
  
      Directory: G:\Temp\System Documents\WindowsPowerShell\Modules
  
  
  ModuleType Version    Name                                ExportedCommands
  ---------- -------    ----                                ----------------
  Binary     2.7.1.7    ISESteroids                         {Get-PSSharperData, Add-SteroidsContextMenuComma...
  Script     1.2        Use-RawPipeline                     {Invoke-NativeCommand, Receive-RawPipeline, Get-...
  
  
      Directory: C:\Program Files\WindowsPowerShell\Modules
  
  
  ModuleType Version    Name                                ExportedCommands
  ---------- -------    ----                                ----------------
  Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValida...
  Script     1.2.4      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider,...
  Script     4.5.0      Pester                              {Describe, Context, It, Should...}
  Script     2.0.4      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Fi...
  Script     2.0.3      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Fi...
  Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHand...
  
  
      Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
  
  
  ModuleType Version    Name                                ExportedCommands
  ---------- -------    ----                                ----------------
  Manifest   1.0.0.0    AppBackgroundTask                   {Disable-AppBackgroundTaskDiagnosticLog, Enable-...
  Manifest   2.0.0.0    AppLocker                           {Get-AppLockerFileInformation, Get-AppLockerPoli...
  Manifest   1.0.0.0    AppvClient                          {Add-AppvClientConnectionGroup, Add-AppvClientPa...
  Manifest   2.0.0.0    Appx                                {Add-AppxPackage, Get-AppxPackage, Get-AppxPacka...
  Script     1.0.0.0    AssignedAccess                      {Clear-AssignedAccess, Get-AssignedAccess, Set-A...
  Manifest   1.0.0.0    BitLocker                           {Unlock-BitLocker, Suspend-BitLocker, Resume-Bit...
  etc...
  </code></pre>
  
  <p>And <code>Get-InstalledModule</code></p>
  
  <pre><code>PS C:\&gt; Get-InstalledModule -Name "PowerShellGet" -RequiredVersion 2.0.3
  PackageManagement\Get-Package : No match was found for the specified search criteria and module names
  'PowerShellGet'.
  At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:9050 char:9
  +         PackageManagement\Get-Package @PSBoundParameters | Microsoft. ...
  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package],
     Exception
      + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
  </code></pre>