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 = 'https://www.powershellgallery.com/api/v2/' PublishLocation = 'https://www.powershellgallery.com/api/v2/package/' ScriptSourceLocation = 'https://www.powershellgallery.com/api/v2/items/psscript' ScriptPublishLocation = 'https://www.powershellgallery.com/api/v2/package/' InstallationPolicy = 'Untrusted' } Register-PSRepository @Repository
… you get the following exception in return:
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.