One of the most useful cmdlets in PowerShell is Install-Module. This cmdlet simplifies downloading and installing modules from the PowerShell repository to your local computer. To use it, simply specify the name of the module after the cmdlet; if the module exists in the repository, it will be installed on your device. By default, latest version of the module is downloaded.
When executing Install-Module, such as Install-Module ExchangeOnlineManagement. PowerShell may prompt an error stating that the NuGet provider is required to continue. PowerShellGet requires NuGet provider version 2.8.5.201 or newer to interact with NuGet-based repositories.
The error message provides a PowerShell command for manually installing the NuGet provider on your device. You can use the command: Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force.
When you Press Y on Do you want PowerShellGet to install
and import the NuGet provider now? You may get below errors:
- WARNING: Unable to download from URI.
- WARNING: Unable to download the list of available providers. Check your internet connection.
- Unable to find package provider ‘NuGet’. It may not be imported yet. Try Get-PackageProvider -ListAvailable.
PowerShell 5.1 is shipped with PowerShellGet version 1.0.0.1, which does not include the NuGet provider by default
Note
Contents
Get PowerShell Version
Check PowerShell version
$psversiontable.PSversion
Major Minor Build Revision
----- ----- ----- --------
5 1 26100 2161
Check PowerShellGet Version
Check the version of PowershellGet
Get-Module PowerShellGet -Listavailable
Get Security Protocols Enabled on Your Computer
Check Enabled security protocols
[Net.ServicePointManager]::SecurityProtocol
Enable TLS 1.2 in your PowerShell session
PowerShell Gallery does not support TLS 1.0 and TLS 1.1 protocols. If you find that enabled on your computer, you can safely disable it. You can temporarily enable and use TLS 1.2 on PowerShell console and in your PowerShell scripts by using the following command:
Enable TLS 1.2 in PowerShell session
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Disable TLS 1.0 and TLS 1.1 |
---|
It’s recommended to disable TLS 1.0 and TLS 1.1 on all your devices. You can refer to the blog posts below for details on how to implement this using various methods on different Windows operating systems. How To Disable TLS 1.0 And TLS 1.1 On Windows Servers. Disable TLS 1.0/TLS 1.1 using PowerShell on Windows 10/11. Disable TLS 1.0 And TLS 1.1 in Windows 10/11. |
Enable Strong Cryptography in .NET 4.5+
To configure .NET Framework to support strong cryptography, use the following PowerShell commands. These commands will make changes to the registry key, so ensure you run them from an elevated version of PowerShell. This is applicable for .NET Framework 4.5 or higher.
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 PowerShell and confirm Security Protocols
After setting the security protocol to TLS 1.2 and configuring the strong cryptography registry keys, restart your PowerShell session and launch it again. Now, check the security protocols once more to confirm the changes.
Check Enabled Security Protocols
[Net.ServicePointManager]::SecurityProtocol
Install the Latest Version of PowerShellGet
You can install NuGet and PowerShellGet using the following commands. Once you install latest version of PowerShellGet, Old versions may not remove automatically. To remove older versions of PowerShell get, refer to the link: Remove Old PowerShellGet.
Install Latest version of NuGet
Install-PackageProvider -Name NuGet -Force
Install PowerShellGet
Install-Module PowerShellGet -AllowClobber -Force
Register PowerShell Gallery as trusted repository
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Download NuGet Provider for PowerShell manually
If the steps provided previously do not resolve the issue, you can also download the NuGet Provider manually using the following link: Download NuGet Provider. This will download Microsoft.PackageManagement.NuGetProvider.dll file which is NuGetProvider dll. The location for NuGet Provider is: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208.
Install NuGet Using PowerShell
To install NuGet using PowerShell, run the following commands:
- Launch PowerShell as an administrator.
- Install NuGet using the Install-PackageProvider cmdlet.
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
This will install NuGet in C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.201.
- Check the NuGet Provider and import it using the Import-PackageProvider cmdlet.
Get-PackageProvider -ListAvailable
Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201
Conclusion
PowerShell Gallery serves as a central repository for storing and sharing PowerShell scripts and modules. Therefore, it’s easy to use the Find-Module command to locate any PowerShell module on the gallery. Once you find a module, you can use the Install-Module command to download and install it on your device.
To meet these requirements, it’s necessary to have the NuGet provider and PowerShellGet installed on your device. Newer versions of PowerShell typically include the NuGet provider. PowerShell 6.0 comes with version 1.6.0 of PowerShellGet, and PowerShell 7.0 comes with version 2.2.3 of PowerShellGet.