Once I got a task that required PowerShell Az modules to be installed on a Windows Server 2008 R2 box. Azure PowerShell modules update quite often and I wasn’t sure if that will work at all.
I found on MS Docs site that there is a need to install at least PowerShell version 5 and .NET version 4 framework. It looks pretty simple in 6 steps:
- Update to Windows PowerShell 5.1. If you’re on Windows 10 version 1607 or higher, you already have PowerShell 5.1 installed.
- Restart
- Install .NET Framework 4.7.2 or later.
- Restart
- Ensure that you have the latest version of PowerShellGet.
Install-Module -Name PowerShellGet -Force
- Install PowerShell module for Azure
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
First 4 are really easy and I was so happy to see that PowerShell became version 5.1.
[PS] C:\>Get-Host | Select-Object Version
Version
-------
5.1.14393.3471
Sometimes everything works perfectly well. To tell the truth – it is a rare case. Usually, some troubleshooting is required.
This time I stuck with the Step 5 – Install PowerShellGet module.
[PS] C:\>Install-Module PowershellGet -Force
NuGet provider is required to continue
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\administrator\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 PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
Surprisingly, there was an error with the Nuget installation.
PS C:\> Install-Module PackageManagement -Force -Repository PSGallery
NuGet provider is required to continue
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\administrator\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 PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
PackageManagement\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 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 char:21
+ ... $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
kageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
vider
PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name
'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 char:21
+ ... $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
ider
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try
'Get-PackageProvider -ListAvailable'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7415 char:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
der], Exception
+ FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
geProvider
Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201'
or newer version of NuGet provider is installed.
At line:1 char:1
+ Install-Module PackageManagement -Force -Repository PSGallery
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Install-Module], InvalidOperationException
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module
To confirm that there is no proxy or any other access issue I opened the same URL https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409 in browser – no issues.
Ok, tried to register the Nuget differently – still got an error.
PS C:\> Register-PackageSource -provider NuGet -name nugetRepository -location "https://www.nuget.org/api/v2"
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.
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
Register-PackageSource : Unable to find package providers (NuGet).
At line:1 char:1
+ Register-PackageSource -provider NuGet -name nugetRepository -locatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-Pac
kageSource], Exception
+ FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource
I knew that Windows Server 2008 R2 crypto-system relies on SSL3 which was not actual in the year 2021 reality and needs to be adjusted.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
To keep the changes there are 2 Registry keys to update.
The following cmdlet will set strong cryptography on 64 bit .Net Framework (version 4 and above) via Registry change.
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
This cmdlet is to set strong cryptography on 32 bit .Net Framework (version 4 and above).
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
After crypto system settings update I successfully installed Nuget.
PS C:\> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Name Version Source Summary
---- ------- ------ -------
nuget 2.8.5.208 https://onege... NuGet provider for the OneGet meta-package manager
Simple command allows to install PowerShell modules using the same method as for Windows 10 and Windows Server 2016.
Register-PSRepository -Default
It might not work well if the server is behind a proxy. If that is the case, you need to configure proxy settings.
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://YourProxyHostNameGoesHere:ProxyPortGoesHere')
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
Run the same command with the proxy configuration completed:
PS C:\> Register-PSRepository -Default
## Confirm that the repository have been successfully added
PS C:\> 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 : {}
Sometimes this command is also required as it blocks modules installation from cloud repositiories.
Register-PackageSource -Name PSNuGet -Location https://www.powershellgallery.com/api/v2 -ProviderName NuGet
After all, I managed to install the required Az module successfully. Hope that works for you too.
Install-Module -Name PowerShellGet -Force
Install-Module PackageManagement -Force -Repository PSGallery
Install-Module -Name Az -Repository PSGallery -Force
Conclusion
In this article, you learned why you are unable to configure NuGet provider, add module repositories for PowerShell to be able to install latest PowerShell modules from online repositories. The cause of all the issues on a way to the result is outdated cryptosystem of Windows Server 2008 R2. The solution to this well known problem is to configure a system to use TLS1.2 or higher and only after that it should start working as expected.
You can find more automation and other things you can do with Powershell here.