> Register-PSRepository -Name PSGallery -SourceLocation 'https://www.powershellgallery.com/api/v2/' -InstallationPolicy Trusted Register-PSRepository : The specified Uri 'https://www.powershellgallery.com/api/v2/' for parameter 'SourceLocation' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements. At line:1 char:1 + Register-PSRepository -Name PSGallery -SourceLocation 'https://www.po ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (https://www.pow...ery.com/api/v2/:String) [Register-PSRepository], ArgumentException + FullyQualifiedErrorId : InvalidWebUri,Register-PSRepository
Wow… what a frustrating error. I’m sure I’ve done this before… What – is – wrong…?
The delay experienced before getting an error felt indicative of a web timeout. And my corporate life lives behind a team of proxies. Certainly I need to set my System.Net.WebClient
proxy before retrieving anything external. I took a look under the hood, and the PowerShellGet module leverages System.Net.WebRequest
. Well, luckily this means we can fix our PowerShellGet repository registration by setting the proxy:
> [system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://foo-bar-baz:8080') > [system.net.webrequest]::defaultwebproxy Address : http://foo-bar-baz:8080/ BypassProxyOnLocal : False BypassList : {} Credentials : UseDefaultCredentials : False BypassArrayList : {} > Register-PSRepository -Name PSGallery -SourceLocation 'https://www.powershellgallery.com/api/v2/' -InstallationPolicy Trusted > find-module xNetworking Version Name Type Repository Description ------- ---- ---- ---------- ----------- 2.10.0.0 xNetworking Module PSGallery Module with DSC Resources for Networking area
Okay… we’re on our way again :)