Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active June 14, 2022 01:10
Show Gist options
  • Save guitarrapc/79d31b8cd02649075642b77c4ae796ab to your computer and use it in GitHub Desktop.
Save guitarrapc/79d31b8cd02649075642b77c4ae796ab to your computer and use it in GitHub Desktop.
Whom you miss PSGallery with Get-PSRepository!
Register-PSRepository -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 Trusted -PackageManagementProvider NuGet
@uemoe
Copy link

uemoe commented Jan 3, 2018

@sir-Higgins Thank you very helpful comment.

@Xeleema
Copy link

Xeleema commented Jan 5, 2018

This helped me set things up on a Windows Server 2012 R2 system, running PowerShell v4.0.

  1. Installed "PackageManagement PowerShell Modules Preview - March 2016"

  2. Ran the following command you provided;

Register-PSRepository -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 Trusted -PackageManagementProvider NuGet

  1. Tested by installing the "SpeculationControl" module from Microsoft's PowerShell Gallery;

Save-Module -Name SpeculationControl -Path C:\Path\To\PowerShell\Modules\

@rautamiekka
Copy link

Register-PSRepository -Default with WMF 5.1 it seems

PS C:\> Register-PSRepository -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 Trusted -PackageManagementProvider NuGet
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
At line:1 char:1
+ Register-PSRepository -Name PSGallery -SourceLocation https://www.pow ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
+ FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository

PS C:\> Register-PSRepository -Default
PackageManagement\Register-PackageSource : Module Repository 'PSGallery' exists.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4211 char:17
+ ... $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceExists: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-PackageSource], Exception
+ FullyQualifiedErrorId : PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource

PS C:\> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2

PowerShell still makes life too hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment