Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active June 14, 2022 01:10
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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
@guitarrapc
Copy link
Author

After run it, you can use Find-Module for PSGallery.

image
image

@davidwallis3101
Copy link

Register-PSRepository -Default with WMF 5.1 it seems

@sir-Higgins
Copy link

sir-Higgins commented Apr 19, 2017

Corporate Proxy
I'm Behind a corporate proxy with windows authentication
I had to run the following lines for Register-PSRepository -Default to work

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://[YourProxyDNS]:[yourProxyPort]') [system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials [system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Powershell Profile
You can add these lignes in your powershell profile

Create the profile file if you don't have one
New-Item -path $PROFILE -type file –force

Edit the profile file
notepad $PROFILE

@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