Related
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.
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"
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).
Good Morning,
I was trying to install Azure powershell to connect to my server. I made sure I was up to date on all my versions. Then I ran the: Install-Module -Name AzureRM -AllowClobber command. Everything downloaded perfectly and was unzipped successfully.
*Then I know I have to load the AzureRM module so I ran the command: Import-Module -Name AzureRM
*After I ran the command nothing happens! I press ENTER but I just get brought down one line like the command does not even exist.
*I ran the (get-command -module azurerm).count and it showed count of 0.
**So from what I gathered it downloaded/unzipped/installed/but will not actually load?
*To make more sense I followed the instructions from the following youtube video: https://www.youtube.com/watch?v=3Q0jG1Doa-s&t=181s
**Any help will be greatly appreciated. Trying to install it to be able to change email names for office 365. Thanks!
PS: I made sure I have version 5.0 of power shell
Version Of Powershell Picture
: https://i.stack.imgur.com/e7ffr.jpg
[Blanks I get after running command. (nothing happens!)]
: https://i.stack.imgur.com/td9Jv.jpg
On the off chance you had the AzureRM module installed already, either open a new Powershell session or run...
Import-Module -Name AzureRM -Force
To double check the module was installed correct, enter...
Get-Module -Name Azure*
Ensure the version is what you want.
When I install AzureRM on a fresh machine, I do...
Get-Module -Name PowerShellGet -ListAvailable | Select-Object -Property Name,Version,Path
Install-Module PowerShellGet -Force
Install-Module -Name AzureRM -AllowClobberso
Import-Module -Name AzureRM
This worked for me on a fresh Windows 10 15063-build.
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"