05 January 2023

Install or update PowerShellGet

To access the PowerShell Gallery, you must use Transport Layer Security (TLS) 1.2 or higher. By default, PowerShell is not configured to use TLS 1.2. Use the following command to enable TLS 1.2 in your PowerShell session.
1
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
There are two ways to install the NuGet provider:

-Use Install-PackageProvider to install NuGet before installing other modules
Run the following command to install the NuGet provider.
1
Install-PackageProvider -Name NuGet -Force
After you have installed the provider you should be able to use any of the PowerShellGet cmdlets with the PowerShell Gallery.

-Let Install-Module prompt you to install the NuGet provider
The following command attempts to install the updated PowerShellGet module without the NuGet provider. Install-PackageProvider -Name NuGet -Force Install-Module prompts you to install the NuGet provider. Type Y to install the provider.
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\user1\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 VERBOSE: 
VERBOSE: Installing NuGet provider.

Note:
If you have not configured TLS 1.2, any attempts to install the NuGet provider and other packages will fail.

After installing PowerShellGet.
After you have installed the new version of PowerShellGet, you should open a new PowerShell session. PowerShell automatically loads the newest version of the module when you use a PowerShellGet cmdlet.

We also recommend that you register the PowerShell Gallery as a trusted repository. Use the following command:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted