I was trying to update some Az modules on a Windows 2016 server (PowerShell version 5.1.14393.3471 for what it's worth) today to connect to some Azure storage and thought I'd run the normal Update-Module to keep things nice and fresh. However, this time it was failing with:
PS C:\Users\Al> Update-Module
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2038 char:13
+ Get-PSGalleryApiAvailability -Repository (Get-SourceName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
+ FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
So running it with a debug gets me this (with some cruft removed):
PS C:\Users\Al>Update-Module -Debug
DEBUG: 00:00:47.3393273 Source 'https://www.powershellgallery.com/api/v2' is not one of the 'NuGet' provider.
...SNIP....
VERBOSE: An error occurred while sending the request.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2' for '2' more times
VERBOSE: An error occurred while sending the request.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2' for '1' more times
VERBOSE: An error occurred while sending the request.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2' for '0' more times
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
...SNIP...
Interesting. Lets just try check the repository is good first:
PS C:\Users\Al> Get-PSRepository
WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
WARNING: Unable to download the list of available providers. Check your internet connection.
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
OK. Well it looks good but that warning is funny. Looking at the firewall logs it showed successful connections to www.powershellgallery.com so it wasn't access out to the internet. Lets try and install the module again.
PS C:\Users\Al> Install-Module -Name Az
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'Az'. Try
Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Bother. At this point, having found three different error messages and being able to download the URL's in the warnings using IE, I looked into some Wireshark dumps and noticed that while the IE was using TLS1.2, this PowerShell was not and failing at the server side to connect properly. Time to enforce TLS1.2 in the PowerShell session with this command:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Rerun the Update-Module and it works. I'm not sure what I might have done to stop it working, perhaps a GPO or some such to set PowerShell to default to TLS1.1 or 1.0 or perhaps PowerShellGallery turned off TLS1.0 and 1.1 support (smart move). You can Google that one to find a better place to put that line so it sticks for each session.
No comments:
Post a Comment