Update powershell to the latest revision

If you have Microsoft's winget app (Windows package manager), you can run the following command to update to the most recent version of PowerShell:

winget install Microsoft.PowerShell

You can never update Windows PowerShell installations on demand - except, in the past, if you upgraded to a new major version, but v5.1 is the last version that will ever be released, given that Windows PowerShell is in maintenance-only will see no new development, unlike its successor, the cross-platform PowerShell (Core) 7+ edition.[1]

Revisions of v5.1 are delivered as part of Windows updates.

However, you can selectively update the PowerShellGet module, in which the problem-causing Register-PSRepository command is defined:

While you normally would just run Update-Module PowerShellGet, a different approach is required the first time, when switching from the bundled PowerShellGet module to the latest version from the PowerShell Gallery:

  • Open an elevated session (Run as Administrator).

  • Execute the following (add -Verbose to get detailed information):

      Install-Module PowerShellGet -Force
    

The -Force is to enable installation even though a module by that name is already installed; you may still see a prompt about downloading the NuGet package provider.
Note that the old PowerShellGet version will linger in a different location, but the new one will take precedence over it.

After this initial switch to the gallery-installed version, you'll be able to use
Update-Module PowerShellGet for future versions.


You can use the Get-Command cmdlet to discover a given command's module of origin; e.g.:

PS> (Get-Command Register-PSRepository).Module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.1.4                 PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}

[1] PowerShell (Core) 7+ versions can be updated on demand - however, as of v7.1, PowerShell [Core] doesn't come with Windows and requires manual installation. However, you can now install and update it via the Microsoft Store application.


Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

Run the following command from command prompt wait till gets downloaded, and it will prompt to installation wizard follow the instructions to install it.


If you're running Windows 11 or have updated App Installer in Windows 10.

Update PowerShell using Windows Package Manager (winget)

winget upgrade Microsoft.PowerShell

You also can install PowerShell by using below command via winget

winget install Microsoft.PowerShell

Learn more:

  • winget in Microsoft Docs
  • winget in GitHub repository