Using VSTS as PowerShell Gallery in Deployments - powershell

I have a feed for PowerShell modules in my VSTS project and I am using it as a private gallery, based on this article:
https://roadtoalm.com/2017/05/02/using-vsts-package-management-as-a-private-powershell-gallery/
Everything works great when we run this on the machine.
I need these modules as part of the release process, so the first task is to register this repo if it doesn't exist and then download and install the latest version of each module.
The relevant part of my script is:
Install-PackageProvider -Name NuGet -Confirm:$false -RequiredVersion 2.8.5.208
Get-PSRepository | Where-Object {$_.Name -eq "MyPrivateFeed" -or $_.SourceLocation -eq "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2"} | Unregister-PSRepository
Register-PSRepository -Name "MyPrivateFeed" -SourceLocation "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2" -InstallationPolicy Trusted
$PAT = $(System.AccessToken) | ConvertTo-SecureString -AsPlainText -Force
$VSTSCredentials = New-Object -TypeName PScredential("dummy", $PAT)
Find-Module -Name * -Repository MyPrivateFeed -Credential $VSTSCredentials | Install-Module -Credential $VSTSCredentials
The PowerShell task in the release fails with:
WARNING: Unable to find module repositories.
PackageManagement\Register-PackageSource : The property 'Values' cannot be
found on this object. Verify that the property exists.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4173
char:17
+ ... $null = PackageManagement\Register-PackageSource #PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Power...erPackageSource
:RegisterPackageSource) [Register-PackageSource], Exception
+ FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Pack
ageManagement.Cmdlets.RegisterPackageSource
The same exact script works on the same machine when I run it on ISE/Console (with replacing the token with the actual PAT of course)
Anyone has any idea what is going on here?
I tried adding -PackageManagementProvider NuGet to Register-PSRepository but that didn't help

I occasionally see the "Register-PackageSource : The property 'Values' cannot be found on this object. Verify that the property exists." error when attempting to run a "Register-PSRepository" command from the PowerShellGet module (or a "Register-PackageSource" command from the dependent PackageManagement module) when there are no package sources currently registered for the "PowerShellGet" package provider (not even the default "PSGallery").
This appears to happen when an empty file exists under the current user's profile at "%USERPROFILE%\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml". I'm not sure what causes that empty file to be created, but until it's deleted, not even the "Register-PSRepository -Default" command will succeed.
Deleting the file does resolve the error and allows PowerShellGet package sources to be registered again.

Related

Download Nuget Package from Github nuget registery using PowerShell, Error : Find-Package: No match was found/

I am trying to download using PowerShell a nuget package from my Github nuget registry, but without success, receiving a weird error message.
First, here's my environment:
Second, here's the code I'm executing:
$patToken = "<MY_PAT_TOKEN>" | ConvertTo-SecureString -AsPlainText -Force -Verbose
$packageSourceCreds = New-Object System.Management.Automation.PSCredential("nuget.pkg.github.com\<MY_USERNAME>", $patToken) -Verbose
$packageSource = Register-PackageSource -Name MyNugetSource -Location $packageSourceUrl -ProviderName NuGet -Trusted -Credential $packageSourceCreds -Verbose
$Find-Package -Name <PACKAGE_NAME> -Source MyNugetSource -Credential $packageSourceCreds -Verbose```
I'm receiving this error saying that:
Find-Package: No match was found for the specified search criteria and package name '<PACKAGE_NAME>'. Try Get-PackageSource to see all available registered package sources.
I'm pretty sure of the correctness of the name of the package and of my credentials, is there something I'm missing or that I'm doing incorrectly ?

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.

Issues with Registering PSRepository and Installing VMWare PowerCLI Module

My Setup: Windows 10.17134, PowerShell 5.1.17134.407
When trying to Register a new PSRepository using the Code below….
Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted
….it gives me the following error:
FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
I am not able to install the VMWare PowerCLI Module with this command:
Save-module -Name vmware.powercli -path c:\temp
….it gives me this error:
FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage
Here are the results of a days googling
I'm running
Register-PSRepository
-Name "PSGallery"
–SourceLocation "https://www.powershellgallery.com/api/v2/"
-InstallationPolicy Trusted
(multiline for clarity)
and I kept getting
Register-PSRepository : Use 'Register-PSRepository -Default' to
register the PSGallery repository. At line:1 char:1
+ Register-PSRepository -Name "PSGallery" –SourceLocation "https://www. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
+ FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
I assumed this was to do with proxy settings so I tried all of the various methods of setting the proxy in powershell to no avail.
Finally I ran
Get-PSRepository
and discovered that the repository was already registered, it was just untrusted
So I ran
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
The original reason I had for doIng this is because when I run
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
I get
Install-PackageProvider : No match was found for the specified search
criteria for the provider 'NuGet'. The package provider requires
'PackageManagement' and 'Provider' tags. Please check if the specified
package has the tags. At line:1 char:1
+ Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider)
[Install-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider
Unfortunately, making the repository trusted did no help with my issue
... and the original reason for doing this was so I could run
Install-Module -Name SqlServer -Force -Verbose -Scope CurrentUser
Which was failing (sorry no error message, it was so long ago)
After all my fiddling however, this statement now works without error.
Not sure if it was all the proxy config, or making NuGet trusted or both
I've been chasing this problem for days. I isolated it to Install-PackageProvider not being able to download:
Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll
In my case, my company does not allow us to download DLLs from the internet without due process. I engaged due process and got an approved copy of the DLL. Then it needs to be placed here:
$env:ProgramFiles\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll
Note the version becomes a folder and is stripped from the name.
Manually doing so eliminates the need to run Install-PackageProvider. Some articles state that Import-PackageProvider is necessary to get PowerShell to recognise it. But, I did not need to do the Import. Just try Install-Module -Name SqlServer -Force again.

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!

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"