Unable to find repository on Update-Module - powershell

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"

Related

Powershell: Unable to update PowerShellGet , error: The version '1.4.7' of module 'PackageManagement' is currently in use

Win10 laptop, in service for a couple years.
I have been stuck on this for a couple of days.
I try this command:
Install-Module –Name PowerShellGet –Force -AllowClobber
Which throws this error:
WARNING: The version '1.4.7' of module 'PackageManagement'
is currently in use. Retry the operation after closing the applications.
I can see in task manager there are no other sessions of powershell running.
I can exit all the sessions, and run this from a plain cmd:
powershell -NoProfile -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"
And I get the SAME error.
OK, so I exit all powershell instances (as seen in Details tab of taskmgr) and do this:
powershell -NoProfile -Command "Uninstall-Module PowerShellGet"
powershell -NoProfile -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"
And I get the same error.
So I do the uninstall again, (which runs without messages or errors). And I take out the big guns... powershell.exe is not running, and I navigate to:
C:\Users\$user\Documents\WindowsPowerShell\Modules\PackageManagement\1.4.7
And I delete the 1.4.7 directory.
And the commands above run with the same behavior and same error.
How do I move past this?
Additional Background:
PS C:\WINDOWS\system32> Get-Module -ListAvailable PowerShellGet,PackageManagement
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.4.7 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script 2.2.5 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...
Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
PS C:\WINDOWS\system32> Get-Module -ListAvailable PowerShellGet,PackageManagement | % path
C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\PackageManagement.psd1
C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\PackageManagement.psd1
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PowerShellGet.psd1
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PowerShellGet.psd1
Also Tried
Limiting scope to current user:
PS C:\WINDOWS\system32> Install-Module -Name PowerShellGet -Force -Scope CurrentUser
WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the
applications.
PS C:\WINDOWS\system32> exit
# OK, check taskmgr that all powershell.exe have exited, and run the below
C:\WINDOWS\system32>powershell -command "Install-Module -Name PowerShellGet -Force -Scope CurrentUser"
WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the
applications.
SOLUTION
I did not track exactly the step, but one of the comments below led to a path that did resolve.
One of the tricks was to watch the process list, and to be sure that all vscode and other powershell-loading process were terminated prior to doing the update.
Apologies I cannot document the exact step that resolved. (I was kind of toast working on this.)
I was able to fix this by running the command below in an admin PowerShell:
Update-Module -Name PowerShellGet -RequiredVersion 2.2.5
Hope this helps others!
Source: https://github.com/PowerShell/PowerShellGetv2/issues/599
I don't have the rep to post a comment, but James Graham's post suggesting using the Update-Module worked for me too. Exact same issue, with the exact same version numbers, almost a year later. Yet, I just checked and there's now a 3.0.12 beta available which requires the code below:
Install-Module -Name PowerShellGet -AllowPrerelease -Force
I tried for a while to figure out the syntax highlighting but to no avail.
I'm using PS 7 and was having the same problem.
Steps I followed to fix the issue...:
Listed module folders using $env:PSModulePath -split ';'. Result was list of paths where modules are stored as per scope (read here for more on the topic).
List of Paths:
- C:\Users\**USER**\OneDrive - Microsoft\Documents\PowerShell\Modules
- C:\ProgramFiles\PowerShell\Modules
- **c:\program files\powershell\7\Modules**
- C:\Program Files\WindowsPowerShell\Modules
- C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
- C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell
look for the folder called PackageManagement (it was in C:\Program Files\PowerShell\7\Modules in my case)
Rename it (don't recommend deleting!)
Get-InstalledModule to make sure I PackageManagement is not there anymore
Install-Module -name PowerShellGet -RequiredVersion 2.2.5 -Force to install PowerShellGet.
and job's a good'un! At least for me :)

Powershell install - No match was found for the specified search criteria and module name

I am having a difficult time installing/updating my powershell modules. I noticed this when I tried installing DBA Tools moudle. Reference links are https://dbatools.io/download/ and https://github.com/sqlcollaborative/dbatools.
It's a corporate PC. But I know that I have installed other modules before in the past. Does anyone have any idea what's going on?
PS (Admin)>
Install-Module DBATools
NOTE: The Install-Module command pauses for many minutes before the command returns a warning message.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
ERROR: "PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PowerShellGet'".
Update-Module PowerShellGet
ERROR: "Update-Module : Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated.".
Update-Module PowerShellGet -Force
ERROR: "Update-Module : Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated.".
Find-Module dbatools
NOTE: The Find-Module command pauses for many minutes before the command returns an error message.
ERROR: "No match was found for the specified search criteria and module name 'dbatools'. Try Get-PSRepository to see all available registered module repositories."
Get-PSRepository | fl *
Name : PSGallery
SourceLocation : https://www.powershellgallery.com/api/v2
Trusted : False
Registered : True
InstallationPolicy : Untrusted
PackageManagementProvider : NuGet
PublishLocation : https://www.powershellgallery.com/api/v2/package/
ScriptSourceLocation : https://www.powershellgallery.com/api/v2/items/psscript
ScriptPublishLocation : https://www.powershellgallery.com/api/v2/package/
ProviderOptions : {}
Get-Module PackageManagement -ListAvailable
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Get-Module -ListAvailable |
Where-Object ModuleBase -like $env:ProgramFiles\WindowsPowerShell\Modules\* |
Sort-Object -Property Name, Version -Descending |
Get-Unique -PipelineVariable Module |
ForEach-Object {
if (-not(Test-Path -Path "$($_.ModuleBase)\PSGetModuleInfo.xml")) {
Find-Module -Name $_.Name -OutVariable Repo -ErrorAction SilentlyContinue |
Compare-Object -ReferenceObject $_ -Property Name, Version |
Where-Object SideIndicator -eq '=>' |
Select-Object -Property Name,
Version,
#{label='Repository';expression={$Repo.Repository}},
#{label='InstalledVersion';expression={$Module.Version}}
}
}
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[Net.ServicePointManager]::SecurityProtocol = "tls12"
Find-Module dbatools
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'dbatools'. Try
Get-PSRepository to see all available registered module repositories.
Invoke-WebRequest https://www.powershellgallery.com/api/v2
Invoke-WebRequest : The underlying connection was closed: The connection was closed unexpectedly.
Some references I tried
windows 10 - Powershell won't install almost any module using install-module - Stack Overflow
Powershell won't install almost any module using install-module
There's a script for that: Install-Module - unable to resolve package source 'https //www.powershellgallery.com/api/v2/'
https://vanbrenk.blogspot.com/2017/09/install-module-unable-to-resolve.html
Update Manually Installed PowerShell Modules from the PowerShell Gallery – Mike F Robbins
https://mikefrobbins.com/2016/06/09/update-manually-installed-powershell-modules-from-the-powershell-gallery/
Update-Module : Module 'PowershellGet' was not installed by using Install-Module, so it cannot be updated. - Evotec
https://evotec.xyz/update-module-module-powershellget-was-not-installed-by-using-install-module-so-it-cannot-be-updated/
I ran into the same error installing different module. My fix was specifying TLS1.2 for the .net Security protocol.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Try running Register-PSRepository -Default
Thanks to Stephen, rouxquasar it worked with below order for me Windows 2016 Datacenter, KB4598243, Execution policy was set properly so didn't have to deal with that.
Enable TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Register the default PS Gallery Repo (may check Get-PSRepository | fl* just incase)
Register-PSRepository -Default
Install-Module dbatools (check Find-Module before to validate)
Use -Force switch if an older version of dbatools exists.
Re-registering PS default repository as an Administrator fixed for me:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Unregister-PSRepository -Name PSGallery
Register-PSRepository -Default
Find-Module dbatools
I have tried register-psrepository and it executed with out any error but after when I try get-psrepository its was still giving same error message "WARNING: Unable to find module repositories.", I tried different option below steps worked for me:
register ps repository with a different name and use the same psgallery api for source location.
Register-PSRepository PSGallery1 -SourceLocation "https://www.powershellgallery.com/api/v2" -InstallationPolicy Trusted
set the repository
Set-PSRepository PSGallery1
now when I check the repository it worked like charm
PSGAllery1 is the Name I have used
Enabled Group Policy to allow scripts and set execution policy to bypass. I am now able to install the module. However, I must run the install with Scope current user and am still unable to install with As Admin powershell.
Module Install
Install-Module DBATools -Scope CurrentUser
Group Policy (Fix)
#*****************
FIX ...
#*****************
## PS (As Admin)
gpedit.msc
# Navigate to: Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell. Change the “Turn on Script Execution”
# Turn on Script Execution > Enabled, Policy "Allow all scripts"
## PS (As Admin)
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass
<#
#*****************
REFERENCE ...
#*****************
Windows PowerShell - the setting is overridden by a policy defined at a more specific scope
https://vladtalkstech.com/2015/03/windows-powershell-updated-execution-policy-successfully-setting-overridden-policy-defined-specific-scope.html
Change the PowerShell MachinePolicy Execution Policy in WS 2012R2
https://vladtalkstech.com/2014/03/change-powershell-machinepolicy-execution-policy-windows-server-2012r2.html
#>
#*****************
CAUSE ...
#*****************
Get-ExecutionPolicy –List
Set-ExecutionPolicy -Scope MachinePolicy Unrestricted
## However, you might have an error saying it can only be done via Group Policy.
## “Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes mustbe set through Group Policy
Try running the powerShell or the WindowsTerminal as administrator, and then re-entering your command before trying any complicated solution, helps most of the time.

Warning while install-module PowerShellGet

While installing PowerShellGet, I perform the following:
Install-PackageProvider Nuget –force –verbose
then I Exit, try running the following:
Install-Module –Name PowerShellGet –Force –Verbose
When I do this, I get the error:
This error occurs when I try to install other modules too, like MSOnline, Azure etc.
I have the latest version of Powershell and also the necessary modules.
I feel that the reason is due to the PowershellGet file.
Is there a way to resolve this issue?
You need to register the PowerShell repository before installing PowerShellGet. Try this
Register-PSRepository -Name “PSGallery” -SourceLocation “https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted

Powershell: How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line?

I'm trying to install pswindowsupdate.2.0.0.4.nupkg from the Powershell command line on a Win 7 computer not connected to the internet. I'm running PS 5.1.14409.1005. I obtained the nupkg from https://www.preview.powershellgallery.com/packages/PSWindowsUpdate/2.0.0.4
The PS command Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg} throws an error message:
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 'C:\Users{my login}\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShell to install and import the NuGet provider now?
Saying 'yes', of course, fails to install the NuGet provider because I'm not connected to the internet.
I obtained nuget.exe (v4.7.0), stored it in 'C:\Program Files\PackageManagement\ProviderAssemblies' and added 'C:\Program Files\PackageManagement\ProviderAssemblies' to my path statement. However, executing Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg} still fails.
What exactly is a NuGet provider? Is it just nuget.exe? How do I obtain and install the Nuget provider (v2.8.5.201 or greater) for PowerShell so I can install this nuget package from the PowerShell command line?
Note: Visual Studio is not in any way involved with my question
Although I've tried all the previous answers, only the following one worked out:
1 - Open Powershell (as Admin)
2 - Run:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3 - Run:
Install-PackageProvider -Name NuGet
The author is Niels Weistra:
Microsoft Forum
I accepted trebleCode's answer, but I wanted to provide a bit more detail regarding the steps I took to install the nupkg of interest pswindowsupdate.2.0.0.4.nupkg on my unconnected Win 7 machine by way of following trebleCode's answer.
First: after digging around a bit, I think I found the MS docs that trebleCode refers to:
Bootstrap the NuGet provider and NuGet.exe
Install-PackageProvider
To continue, as trebleCode stated, I did the following
Install NuGet provider on my connected machine
On a connected machine (Win 10 machine), from the PS command line, I ran Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.208 -Force. The Nuget software was obtained from the 'Net and installed on my local connected machine.
After the install I found the NuGet provider software at C:\Program Files\PackageManagement\ProviderAssemblies (Note: the folder name \ProviderAssemblies as opposed to \ReferenceAssemblies was the one minor difference relative to trebleCode's answer.
The provider software is in a folder structure like this:
C:\Program Files\PackageManagement\ProviderAssemblies
\NuGet
\2.8.5.208
\Microsoft.PackageManagement.NuGetProvider.dll
Install NuGet provider on my unconnected machine
I copied the \NuGet folder (and all its children) from the connected machine onto a thumb drive and copied it to C:\Program Files\PackageManagement\ProviderAssemblies on my unconnected (Win 7) machine
I started PS (v5) on my unconnected (Win 7) machine and ran Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.208 to import the provider to the current PowerShell session.
I ran Get-PackageProvider -ListAvailable and saw this (NuGet appears where it was not present before):
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, PublishLocati...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
Create local repository on my unconnected machine
On unconnected (Win 7) machine, I created a folder to serve as my PS repository (say, c:\users\foo\Documents\PSRepository)
I registered the repo: Register-PSRepository -Name fooPsRepository -SourceLocation c:\users\foo\Documents\PSRepository -InstallationPolicy Trusted
Install the pswindowsupdate NuGet package
I obtained and copied the nupkg pswindowsupdate.2.0.0.4.nupkg to c:\users\foo\Documents\PSRepository on my unconnected Win7 machine
I learned the name of the module by executing Find-Module -Repository fooPsRepository
Version Name Repository Description
------- ---- ---------- -----------
2.0.0.4 PSWindowsUpdate fooPsRepository This module contain functions to manage Windows Update Client.
I installed the module by executing Install-Module -Name pswindowsupdate
I verified the module installed by executing Get-Command –module PSWindowsUpdate
CommandType Name Version Source
----------- ---- ------- ------
Alias Download-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Get-WUInstall 2.0.0.4 PSWindowsUpdate
Alias Get-WUList 2.0.0.4 PSWindowsUpdate
Alias Hide-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Install-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Show-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias UnHide-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Alias Uninstall-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Cmdlet Add-WUServiceManager 2.0.0.4 PSWindowsUpdate
Cmdlet Enable-WURemoting 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUApiVersion 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUHistory 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUInstallerStatus 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUJob 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WULastResults 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WURebootStatus 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUServiceManager 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUSettings 2.0.0.4 PSWindowsUpdate
Cmdlet Get-WUTest 2.0.0.4 PSWindowsUpdate
Cmdlet Invoke-WUJob 2.0.0.4 PSWindowsUpdate
Cmdlet Remove-WindowsUpdate 2.0.0.4 PSWindowsUpdate
Cmdlet Remove-WUServiceManager 2.0.0.4 PSWindowsUpdate
Cmdlet Set-WUSettings 2.0.0.4 PSWindowsUpdate
Cmdlet Update-WUModule 2.0.0.4 PSWindowsUpdate
I think I'm good to go
MSDocs state this for your scenario:
In order to execute the first time, PackageManagement requires an
internet connection to download the Nuget package provider. However,
if your computer does not have an internet connection and you need to
use the Nuget or PowerShellGet provider, you can download them on
another computer and copy them to your target computer. Use the
following steps to do this:
Run Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force to install the provider from a computer with an internet connection.
After the install, you can find the provider installed in $env:ProgramFiles\PackageManagement\ReferenceAssemblies\\\<ProviderName\>\\\<ProviderVersion\>
or
$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies\\\<ProviderName\>\\\<ProviderVersion\>.
Place the folder, which in this case is the Nuget folder, in the corresponding location on your target computer. If your
target computer is a Nano server, you need to run
Install-PackageProvider from Nano Server to download the correct Nuget
binaries.
Restart PowerShell to auto-load the package provider. Alternatively, run Get-PackageProvider -ListAvailable to list all
the package providers available on the computer. Then use
Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 to
import the provider to the current Windows PowerShell session.
Try this:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider NuGet -Force
Set-PSRepository PSGallery -InstallationPolicy Trusted
The provider is bundled with PowerShell>=6.0.
If all you need is a way to install a package from a file, just grab the .msi installer for the latest version from the github releases page, copy it over to the machine, install it and use it.
Here is the script I use in a Dockerfile based on windows/servercore to achieve complete PowerShellGallery setup through Artifactory mirrors (also for onegetcdn.azureedge.net)
ARG ONEGET_NUGET_PROVIDER="Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll"
ARG ONEGET_PROVIDERS="https://artifactory/artifactory/generic-azureedge-onegetcdn/providers/"
RUN $ProviderPath = 'C:/Program Files/PackageManagement/ProviderAssemblies/'; `
New-Item -ItemType "directory" -Path $ProviderPath -Force; `
Invoke-WebRequest -Uri "${Env:ONEGET_PROVIDERS}${Env:ONEGET_NUGET_PROVIDER}" -OutFile "${ProviderPath}${Env:ONEGET_NUGET_PROVIDER}"; `
Register-PSRepository -Name "artifactory-powershellgallery-remote" -SourceLocation "https://artifactory/artifactory/api/nuget/powershellgallery-remote"; `
Unregister-PSRepository -Name PSGallery;
Location and dll version are visible at https://onegetcdn.azureedge.net/providers/providers.masterList.feed.swidtag
None of the options in this thread worked for me. I'm using PowerShell Core 7.1.5. What worked for me was to remove Windows Powershell Modules from $env:PSModulePath. Essentially, check your environment variables and look for any path that has "WindowsPowerShell" and remove it.
In order to install the Nuget Package Manager non-interactively, simply use the -Force flag which bypasses prompting:
Install-PackageProvider NuGet -Force
You do not have to use the trick about the security protocol, at least for Windows Powershell (5.1).

WARNING: Unable to find module repositories

I tried to install Docker on activated windows server 2016 standard.
I executed “Install-Module -Name DockerMsftProvider -Repository PSGallery -Force” but failed. It suggested that can not find PSGallery. I executed "Get-PSRepository".
The error:
WARNING: Unable to find module repositories.
I googled 3 ways to solve it but none of them worked.
I executed Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Verbose -Force successfully.
I installed chocolatey successfully.
I execute "powershell Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted" but failed. It asked me to use "Register-PSRepository -Default".
I tried "powershell Register-PSRepository -Default -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted" but still failed.
How can I solve this problem?
With the deprecation of TLS 1.0 and 1.1 for PowerShell Gallery as of April 2020, the cmdlets Update-Module and Install-Module became broken. Thus, according to this article, some commands need to be executed to bring them alive again:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck
If that still doesn't work, then run the following commands:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Register-PSRepository -Default -Verbose
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
TLS 1.0 and 1.1 were also recently deprecated at NuGet.org:
But that was also previously announced.
Simply running Register-PSRepository -Default (without any additional parameters) worked for me. After that, the Gallery was successfully registered:
PS C:\Windows\system32> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2/
My problem was the missing Proxy config
best solution from comments:
https://www.zerrouki.com/working-behind-a-proxy/
thanks to #Vadzim
In PowerShell open Profile
PS> notepad $PROFILE
this opens Notepad with your profile setting, will be created of not exists.
then add:
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://webproxy.yourCompany.com:PORT')
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
somehow my local proxy is set but doesn't work.
same problem later with Docker, =>
> PS> [Environment]::SetEnvironmentVariable("HTTP_PROXY", http://username:password#proxy:port/", [EnvironmentVariableTarget]::Machine)
then restart docker service
I got a similar message. I ran Register-PSRepository -default and it registered ok. Then I ran Set-PSRepository -Name PSGallery -InstallationPolicy Trusted. I didn't combine the commands, but it worked.
I spent over an hour trying to pass credentials to the proxy the same way I do for Exchange Online, but no love. I disconnected and used our guest WiFi instead.
One more thing which hasn't been mentioned.
You would indeed need to run
notepad $profile
and copy paste this bit changing your proxy details:
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://webproxy.yourCompany.com:PORT')
[system.net.webrequest]::defaultwebproxy.credentials = System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
But if you have HTTPS Inspection turned on, you might want to add the Man-in-the-middle Certificate to the "Trusted Root Certification Authorities"