Restore Default PowerShell Gallery Repository

If you’ve accidentally deleted the PowerShell Gallery (PSGallery) repository from your system, you can restore it using the following command.

Register-PSRepository -Default

In fact, if you try to re-register the PowerShell Gallery using the same method that you’d register a custom repository (see below) …

$Repository = @{
Name = 'PSGallery'
SourceLocation = ''
PublishLocation = ''
ScriptSourceLocation = ''
ScriptPublishLocation ''
InstallationPolicy = 'Untrusted'
Register-PSRepository @Repository

… you get the following exception in return:

Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.