-
-
Save guitarrapc/79d31b8cd02649075642b77c4ae796ab to your computer and use it in GitHub Desktop.
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 |
@sir-Higgins Thank you very helpful comment.
This helped me set things up on a Windows Server 2012 R2 system, running PowerShell v4.0.
-
Installed "PackageManagement PowerShell Modules Preview - March 2016"
-
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
- Tested by installing the "SpeculationControl" module from Microsoft's PowerShell Gallery;
Save-Module -Name SpeculationControl -Path C:\Path\To\PowerShell\Modules\
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.
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