Setting the proxy used for PowerShell Gallery

Written by Troy on July 18, 2016 Categories: Uncategorized Tags: 
> Register-PSRepository -Name PSGallery -SourceLocation '' -InstallationPolicy Trusted

Register-PSRepository : The specified Uri '' 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: ( [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:

> []::defaultwebproxy = new-object'http://foo-bar-baz:8080')

> []::defaultwebproxy

Address               : http://foo-bar-baz:8080/
BypassProxyOnLocal    : False
BypassList            : {}
Credentials           :
UseDefaultCredentials : False
BypassArrayList       : {}

> Register-PSRepository -Name PSGallery -SourceLocation '' -InstallationPolicy Trusted

> find-module xNetworking

Version    Name            Type       Repository           Description
-------    ----            ----       ----------           -----------   xNetworking     Module     PSGallery            Module with DSC Resources for Networking area

Okay… we’re on our way again :)

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>