Published in Articles on by Michiel van Oosterhout ~ 3 min read
As we've seen in an earlier article about PowerShell package management, the package management providers built into Windows 11 are likely to be incomplete and outdated. A few commands are required to fix this. We will focus only on the PowerShellGet package management provider, and its dependency, the NuGet provider, since those should be in place and up-to-date for the regular maintenance of Windows 11.
NuGet package provider
To check the availability and version of package management providers on your system, run Get-PackageProvider
. Typically the NuGet provider is missing. So let's install that first:
(This script requires an elevated Windows PowerShell session.)
# Install the missing NuGet provider (typically installs version 2.8.5.208)
$provider = Install-PackageProvider -Name NuGet -Force
PowerShellGet package provider
The PowerShellGet provider that comes built-in is version 1.0.0.1
, but the latest stable version is 2.2.5
. If we try to install a newer version using Install-PackageProvider -Name PowerShellGet
we get this warning:
WARNING: Version
1.0.0.1
of module PowerShellGet is already installed atC:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1
. To install version2.2.5
, runInstall-Module
and add the-Force
parameter, this command will install version2.2.5
side-by-side with version1.0.0.1
.
The suggestion to use Install-Module
instead of Install-PackageProvider
indicates that, unlike the NuGet provider, the PowerShellGet provider is distributed as a PowerShellGet module. The sugestion to use Install-Module
for a side-by-side install, instead of Update-Module
for an in-place upgrade, indicates that the built-in module cannot be updated. Indeed, if we try by running Update-Module -Name PowerShellGet
, we get this error:
Module PowerShellGet was not installed by using
Install-Module
, so it cannot be updated.
The same is true for the PackageManagement module (try running Update-Module -Name PackageManagement
and you'll get a similar error).
The Windows PowerShell script below installs the latest version of the PowerShellGet module, and of the PackageManagement module, on which it depends, side-by-side with the built-in modules.
(This script requires an elevated Windows PowerShell session.)
# Trust the PowerShell Gallery package source
$source = Set-PackageSource -Name "PSGallery" -Trusted
# Install the latest version of the PowerShellGet module
$version = (Find-Module -Name PowerShellGet).Version
$module = Install-Module -Name PowerShellGet -RequiredVersion $version -Force
# Confirm
$version = (Get-Module -Name PackageManagement).Version
Write-Host "PackageManagement module is at version $version."
$version = (Get-PackageProvider -Name PowerShellGet).Version
Write-Host "PowerShellGet package provider is at version $version."
Notice that the PowerShellGet module is not listed as a module, even after installing the latest version side-by-side. To get its version we have to query it as a package provider instead.
Summary
Windows 11's built-in package management feature is incomplete and outdated. This can be fixed relatively easily, but you have to know a few implementation details to get this right. Luckily this should be a one-time fix.