Error trying to import Nuget PackageProvider - powershell

I have a computer behind a proxy and trying to get the Nuget package provider installed. I ran Install-PackageProvider -Name Nuget on a different PC on a different network and copied Nuget folder to $env:ProgramFiles\PackageManagement\ProviderAssemblies.
If I run Get-PackageProvider -ListAvailable it shows Nuget available.
PS C:\Windows\system32> Get-PackageProvider -ListAvailable
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
nuget 2.8.5.204
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, S...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSy...
However when I try to run Import-PackageProvider -Name Nuget I get the following error:
PS C:\Windows\system32> Import-PackageProvider -Name Nuget
Import-PackageProvider : No match was found for the specified search criteria and provider name 'Nuget'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.At line:1 char:1
+ Import-PackageProvider -Name Nuget
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Nuget:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider
Any suggestions? Thank you!

I was able to work around the proxy by using the following:
$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.Proxy.Address = "http://proxyurl"
Once I did this I was able to use Install-PackageProvider Nuget to install the proivder.

Related

The term 'New-AzureRmUserAssignedIdentity' is not recognized as the name

I'm trying to create user assigned identity, the documentation says that 6.13 should include this function: https://learn.microsoft.com/en-us/powershell/module/azurerm.managedserviceidentity/new-azurermuserassignedidentity?view=azurermps-6.13.0
I uninstalled old versions of Azure RM and installed the latest:
PS C:\Users\user> Get-Module AzureRM -ListAvailable | Select-Object -Property Name,Version,Path
Name Version Path
---- ------- ----
AzureRM 6.13.1 C:\Program Files\WindowsPowerShell\Modules\AzureRM\6.13.1\AzureRM.psd1
But when I try to use it I get the following error:
PS C:\Users\zakima> New-AzureRmUserAssignedIdentity -ResourceGroupName PSRG -Name ID1
New-AzureRmUserAssignedIdentity : The term 'New-AzureRmUserAssignedIdentity' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ New-AzureRmUserAssignedIdentity -ResourceGroupName PSRG -Name ID1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-AzureRmUserAssignedIdentity:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Am I missing some config setting?
The New-AzureRmUserAssignedIdentity Cmdlet resides in the AzureRM.ManagedServiceIdentity module. This module in turn can be found in the PowerShell Gallery and can be installed via:
Install-Module -Name "AzureRM.ManagedServiceIdentity" -AllowPrerelease
Note that the AllowPrerelease flag for Install-Module might not be available for your installed PowerShellGet version, so you might need to update it before the above would work:
Install-Module "PowerShellGet" –Repository "PSGallery" –Force
The problem is that UserAssignedIdentity is still in preview and apparently is not included in AzureRM package.
The following steps made it work for me:
Move to Az package (note - you need uninstall AzureRM first!). It still doesn't include New-AzUserAssignedIdentity.
Install Az.ManagedServiceIdentity directly by running this command:
Install-Module -Name Az.ManagedServiceIdentity
Enjoy!

Powershell won't install almost any module using install-module

My Powershell v5.1 won't install almost any module automatically using install-module whereas manually installation does work.
First, when I run install-module, it would download the module then throw an error, say the pscx module:
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
What I can do now is to manually download the module and use import-module myself. The error occurs almost every time when I'm trying to install any module through this cmdlet. How can I address this problem?
For troubleshooting, Get-PSRepository gives me this:
PS C:\> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
GalleryRolling Trusted https://www.poshtestgallery.com/api/v2/
EDIT:
Got the same error when trying to use Save-Module:
PS C:\> 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
It downloaded the package then displays the WARNING.
When using the Find-Module alone, the result is:
PS C:\> Find-Module -Name 'pscx'
Version Name Repository Description
------- ---- ---------- -----------
3.3.2 Pscx PSGallery PowerShell Community Extensi...
EDIT 2:
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?
EDIT 3: #Sage Pourpre
Debugging log
I Always run PS as administrator.
-Scope CurrentUser throws the same error.
Both PS C:\> Uninstall-Module -Name "PowerShellGet" and PS C:\> Uninstall-Script -Name "PowerShellGet" -RequiredVersion 2.0.3 produce the same result.
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
... $null = PackageManagement\Uninstall-Package #PSBoundParameters
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstal
l-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
Then I tried to list available modules:
PS C:\> 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...
And Get-InstalledModule
PS C:\> 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
Finally solved by:
[Net.ServicePointManager]::SecurityProtocol = "tls12"
The solution is from the following blog posted by vanBrenk:
Trying to install a PowerShell module behind a proxy? Chances are you're getting this error: "Unable to resolve package source 'https://www.powershellgallery.com/api/v2/'". Turns out it isn't allowed through your proxy server [...] Now every command you run is sent and allowed through the proxy.
If you are just using the default repo, there is not reason to specify it.
Try it this way...
Find-Module -Name 'pscx' |
Save-Module -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
Install-Module -Name 'pscx'
You can have multiple version of PowerShell on the same site, it should not impact installing modules, generally.

Unable to find repository on Update-Module

I'm using Windows 10 and Powershell 5.1
Get-PSRepository has result :
PSGallery Untrusted https://www.powershellgallery.com/api/v2
whereas Update-Module returns error
PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2/'. Use
Get-PSRepository to see all available repositories.
At C:\Program Files\WindowsPowerShell\Modules\powershellget\2.0.1\PSModule.psm1:13000 char:20
+ ... $sid = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
ception
+ FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Any idea of how to fix it?
TL;DR
It looks like the URL for the PSGallery repository registered in PowerShell used to point to https://www.powershellgallery.com/api/v2/ but it was changed to https://www.powershellgallery.com/api/v2 at some point (note the missing forward slash at the end).
λ Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
Any modules installed from the old URL are now failing to update. Reinstalling them from PowerShell gallery will update the repository URL, allowing the modules to be updated normally going forward. You can use the following command to reinstall all modules pointing to the old URL:
Get-InstalledModule `
| ? { $_.Repository -eq 'https://www.powershellgallery.com/api/v2/' } `
| % { Install-Package -Name $_.Name -Source PSGallery -Force -AcceptLicense }
The full run down
I have run into this incredibly annoying issue myself. From the error message we can see a couple of things:
PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2/'
PowerShellGet\Update-Module ultimately passes the buck to
PackageManagement\Install-Package
It is looking for a repository
at 'https://www.powershellgallery.com/api/v2/'
Running Get-PSRepository on my machine yields:
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
So it looks like the repository is there, except, maybe it isn't. Take note of the trailing forward slash. Could it be that Install-Package is looking for a repository with a SourceLocation that exactly matches that string? Let's try changing the SourceLocation for PSGallery:
Set-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
PackageManagement\Set-PackageSource : The PSGallery repository has
pre-defined locations. The 'Location, NewLocation or SourceLocation'
parameter is not allowed, try again after removing the 'Location,
NewLocation or SourceLocation' parameter. At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:11768
char:17
+ ... $null = PackageManagement\Set-PackageSource #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (https://www.pow...ery.com/api/v2/:String) [Set-PackageSource],
Exception
+ FullyQualifiedErrorId : ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource
Well, that didn't work. Looks like the PSGallery repository is protected for your safety.
Let's trying adding a different repository and updating a module:
Register-PSRepository -Name PSGallery1 -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
Update-Module -Name pester -Force
Look, no error. It works!
Here is the interesting thing, if I pull up a list of installed modules I find a mix of repositories:
Get-InstalledModule | Select Name, Repository | FT -AutoSize
Name Repository
---- ----------
7Zip4Powershell PSGallery
AWSPowerShell PSGallery
cChoco PSGallery1
dbatools PSGallery
DLMAutomation PSGallery1
InvokeBuild PSGallery1
Microsoft.PowerShell.Archive PSGallery1
PackageManagement PSGallery
Pester PSGallery1
posh-git PSGallery1
powershell-yaml PSGallery1
PowerShellGet PSGallery
PowerUpSQL PSGallery1
psake PSGallery1
PsHosts PSGallery1
psTrustedHosts PSGallery1
ReverseDSC PSGallery1
SeeShell PSGallery1
SqlServer PSGallery1
TunableSSLValidator PSGallery1
xSmbShare PSGallery1
xWebAdministration PSGallery1
Look at all those modules installed form PSGallery1 which is associated with https://www.powershellgallery.com/api/v2/! Prior to just now, there has never been a repository on my machine called PSGallery1; every module I have ever installed has been from PSGallery. My guess is that the PSGallery repository used to point to https://www.powershellgallery.com/api/v2/ and at some point, intentionally or not, it was changed to https://www.powershellgallery.com/avp/v2; breaking Update-Module for any modules installed from the previous URL. I suspect that if I reinstall the modules using Install-Package from the updated PSGallery repository everything will resolve itself and I can remove the PSGallery1 repository.
Let's update all the modules that were deployed from the old URL (PSGallery1):
Get-InstalledModule `
| ? { $_.Repository -eq 'PSGallery1' } `
| % { Install-Package -Name $_.Name -Source PSGallery -Force -AcceptLicense }
Running Get-InstalledModule again yields:
Name Repository
---- ----------
7Zip4Powershell PSGallery
AWSPowerShell PSGallery
cChoco PSGallery
dbatools PSGallery
DLMAutomation PSGallery
InvokeBuild PSGallery
Microsoft.PowerShell.Archive PSGallery
PackageManagement PSGallery
Pester PSGallery
posh-git PSGallery
powershell-yaml PSGallery
PowerShellGet PSGallery
PowerUpSQL PSGallery
psake PSGallery
PsHosts PSGallery
psTrustedHosts PSGallery
ReverseDSC PSGallery
SeeShell PSGallery
SqlServer PSGallery
TunableSSLValidator PSGallery
xSmbShare PSGallery
xWebAdministration PSGallery
Great! Now let's try removing the PSGallery1 repository and updating a module:
Unregister-PSRepository PSGallery1
Update-Module -Name pester -Force
Success! The module updated without error.
I'm not sure what is broken here, the URL for the PSGallery repository or Install-Package, but reinstalling all modules that were installed from the old URL seems to fix everything.
After trying all kinds of things, forcing a reinstall of the NuGet package provider seems to have cleared up the issue with Update-Module for me.
Execute this in an elevated PowerShell session:
Install-PackageProvider Nuget –Force
For reference, I was here when I had my best success:
https://learn.microsoft.com/en-us/powershell/scripting/gallery/installing-psget
I had the same problem and found this question. I tried everything that Jason Boyd (above) wrote about, but it did not work.
Searched some more and found this link https://community.spiceworks.com/topic/2265662-powershell-get-download-problem
where it said TLS 1.0 could be the culpit. It suggests running
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
After that, I was able to update my packages.
The combination of the above answers fixed it for me.
PS> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS> Install-PackageProvider Nuget –Force
PS> Install-Module -Name PSWindowsUpdate
You may need to remove the old version of PSWindowsUpdate first to install the new version.
You can do a -force and it would install two versions side-by-side, but that probably isn't the best idea.
I have the same problem with Windows Powershell 5.1.17134.407 and also tested on the same machine on PowerShell 6.1. Update-Module works as expected with PowerShell 6.1 with the same version of the PowerShellGet module in both Windows PowerShell and PowerShell. So, it looks like the problem is unique to Windows PowerShell and making a guess without further testing, is a problem within the Update-Module code in the PowerShellGet module itself when running on Windows PowerShell.
I don't have a solution for you using Update-Module but as a work around you can use Install-Module instead with the -AllowClobber parameter. It does not fail with this error like Update-Module does. And, right now at least, the end result will be the same since Update-Module actually just installs a new version side-by-side with any older version(s) that are installed per my testing and per https://github.com/PowerShell/PowerShellGet/issues/213.
...
After doing some further testing I happened to reboot the system I was testing on. After reboot the issue with Update-Module in Windows PowerShell 5.1 was resolved - Update-Module now works as expected. I cannot say for sure that the reboot is what resolved it, but it is now resolved.
I tried this but i did get the PSGaller2 thing going.
So i looked further for a sollution. Since i am in a VPN / Proxy envirenmont i did not get the updated to work. When i dit this it worked for me.
$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
I found similar issue. In my case, it was happening due to TLS.
I followed below steps to resolve the issue as follows:
1. Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type Dword
set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type Dword
Restart PS console
Check for supported protocols by using[Net.ServicePointManager]::SecurityProtocol
Register Default Register-PSRepository -Default
Try this:
[System.Net.WebRequest]::DefaultWebProxy.Credentials = System.Net.CredentialCache]::DefaultCredentials
get-psrepository
register-psrepository -default
Fix:
Install-Module -Name PowershellGet -Repository PSGallery -Force
Close the existing PowerShell or ISE session and start a new one
Update-Module
For me these is the code that worked:
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
$env:Path += ";C:\ProgramData\chocolatey\bin"

Module available but not reported as installed

Using PowerShell (version 5.1.17134.228), found some unexpected differences between Get-Module and Get-InstalledModule, in that some modules that I'd expect to be returned by Get-InstalledModule are not.
As an example:
Get-Module -ListAvailable -Name 'Hyper-V'
Get-InstalledModule -Name 'Hyper-V'
Output:
PS C:\> Get-Module -ListAvailable -Name 'Hyper-V'
Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 2.0.0.0 Hyper-V {Add-VMAssignableDevice, Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMGpuPartitionAdapter...}
Binary 1.1 Hyper-V {Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMHardDiskDrive, Add-VMMigrationNetwork...}
PS C:\> Get-InstalledModule -Name 'Hyper-V'
PackageManagement\Get-Package : No match was found for the specified search
criteria and module names 'Hyper-V'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.5\PSModule.psm1:9125 char:9
+ PackageManagement\Get-Package #PSBoundParameters | Microsoft. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
As you can see, the Get-Module command is returning a local path of the Hyper-V modules, so it's definitely installed locally, but Get-InstalledModule cannot find the module.
Is this a bug or have I misunderstood what Get-InstalledModule is meant to do?

Install-PackageProvider is not recognized as the name of a cmdlet, function, script file, or operable program

I'm following Get Started with the PowerShell Gallery which states that the PowerShellGet module exists in Windows 10 (which I am using - build 14721). To confirm, I am running PowerShell v5:
>$PSVersionTable
Name Value
---- -----
PSVersion 5.0.14271.1000
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14271.1000
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Get Started with the PowerShell Gallery states:
PowerShellGet also requires the NuGet provider to work with the PowerShell Gallery. You will be prompted to install the NuGet provider automatically upon first use of PowerShellGet if the NuGet provider is not in one of the following locations:
•$env:ProgramFiles\PackageManagement\ProviderAssemblies
•$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies
I don't have anything in those locations:
>ls $env:LOCALAPPDATA\PackageManagement\ProviderAssemblies
>ls $env:ProgramFiles\PackageManagement\ProviderAssemblies
ls : Cannot find path 'C:\Program Files\PackageManagement\ProviderAssemblies' because it does not exist.
At line:1 char:1
+ ls $env:ProgramFiles\PackageManagement\ProviderAssemblies
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program File...viderAssemblies:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Get Started with the PowerShell Gallery then states:
Or, you can run Install-PackageProvider -Name NuGet -Force to automate the download and installation of the NuGet provider.
If I try that:
>Install-PackageProvider -Name NuGet -Force
Install-PackageProvider : The term 'Install-PackageProvider' is not recognized as the name of a cmdlet, function, script file, or operable program.
correct and try again.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-PackageProvider:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I'm very confused. I have PowerShell v5 but it seems I don't have everything that's supposed to be there, namely PowerShellGet.
Can someone explain why?
When I did Get-Module -ListAvailable -Name PackageManagement, as Adam Bertram suggested, I found that there was a different version in my home folder, cruft from a previous install of Windows that got copied across to a new machine:
> Get-Module -ListAvailable -Name PackageManagement
Directory: C:\Users\<myusername>\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.4.7 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa..
Deleting this version, or before that just forcing the system version to be used with Import-Module PackageManagement -RequiredVersion 1.0.0.1, allowed me to get the NuGet provider installed.
"Install-PackageProvider" was not introduced until PowerShell 5.1
This error means that PowerShell can't find the module that Install-PackageProvider is a part of. Install-PackageProvider is a member of the PackageManagement module. To verify this, run Get-Module
Get-Module -ListAvailable -Name PackageManagement
If this errors out, you'll need to ensure you have the PackageManagement folder a folder inside of your $env:PSModulePath. Here's a quick way to look through each of the folders for the PackageManagement folder.
$env:psmodulepath.Split(';') | foreach {gci $_ -filter '*packagemanagement*'}
If nothing comes back, you don't even have the PackageManagement module folder anywhere where it can be auto-imported by PowerShell.
If that's the case, I'd recommend to reinstall PowerShell v5 RTM.
I had to open up the folder
Directory: C:\Users<myusername>\Documents\WindowsPowerShell\Modules
and rename/delete the PackageManagement folder
Then everything started working more better.
On my Win2019, Get-PackageProvider (with capital letters) didn't work but get-packageprovider did.
This Powershell that should be "the" solution always surprises me :-/