4

I'm having an issue with PowerShell. It's almost like it's not installed all the way; which is weird since it's Windows 10 and it ships with it.

With no lock, I've tried replacing the following directories with a fresh copy from another Windows 10 machine that is working:

  • C:\Users\UserName\AppData\Local\PackageManagement
  • C:\Program Files\WindowsPowerShell
  • C:\Program Files (x86)\WindowsPowerShell
  • C:\Windows\System32\WindowsPowerShell

I also tried SFC /scannow, but it found no issues. I've searched for hours and haven't been able to find anyone with the exact same issue. Does anyone have any ideas?

System Information:

PS C:\WINDOWS\system32> [environment]::OSVersion.Version
Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      10586  0

PS C:\WINDOWS\system32> $PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  122

Errors:

PS C:\WINDOWS\system32> Get-PSRepository
PackageManagement\Get-PackageSource : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:3544 char:31
+ ... ckageSources = PackageManagement\Get-PackageSource @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument:(Microsoft.Power...etPackageSource:GetPackageSource) [Get-PackageSource
   ], Exception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource

PS C:\WINDOWS\system32> Get-PackageProvider -Name PSModule -ForceBootstrap
Get-PackageProvider : Unable to find package provider 'PSModule'. It may not be imported yet. Try 'Get-PackageProvider
-ListAvailable'.
At line:1 char:1
+ Get-PackageProvider -Name PSModule -ForceBootstrap
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
   der], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
   geProvider

The below returns nothing:

PS C:\WINDOWS\system32> Get-PackageProvider -ListAvailable
PS C:\WINDOWS\system32>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TB.
  • 41
  • 1
  • 1
  • 3

2 Answers2

3

If your end goal is to install packages from Chocolatey or something similar with PowerShell you would want to perform the following.

To import the Module you would execute the following:

Import-Module PackageManagement

To install the package providers you would execute the following:

Install-PackageProvider -Name Chocolatey -Force

To find a package within the package provider Chocolatey you would execute the following (you could use wildcard for name to get all packages available):

Find-Package -Name SomePackageNameHere -ProviderName Chocolatey

Lastly, to install a package from Chocolatey you would execute the following:

Install-Package -Name SomePackageNameHere -ProviderName Chocolatey -Force

I hope this helps!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tyler Helder
  • 594
  • 3
  • 11
  • Thanks for the reply Tyler, but that wouldn't have resolved my issue since the system did not see any package repositories installed or see the package provider PSModule. – TB. Jun 09 '16 at 02:28
  • These answers all assume the user can access the internet. This is an error that comes up when no internet is available. – Jamie Jul 26 '20 at 18:48
0

Looks like I solved the issue. I installed Chocolatey by using the CMD.exe method.

I ran CMD.exe as an administrator and ran the following command:

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

Now I have a PS Repository: PS C:\WINDOWS\system32> Get-PSRepository

Name                      PackageManagementProvider InstallationPolicy   SourceLocation
----                      ------------------------- ------------------   --------------
PSGallery                 NuGet                     Untrusted            https://www.powershellgallery.com/api/v2/

I'm guessing something during the install of Chocolatey, repaired whatever was broken.

TB.
  • 41
  • 1
  • 1
  • 3
  • 1
    I forgot, I did have an issue after installing Chocolaty when I tried to run the `choco` command. Error: `The registered delegate for type IXmlService threw an exception. The registered delegate for type IHashProvider threw an exception. Exception has been thrown by the target of an invocation.` The following link resolved the issue: https://github.com/chocolatey/choco/issues/446 Set the following Key to: 0 `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy\Enabled` – TB. May 27 '16 at 04:43