Recovering the PsGallery Repository behind a Corporate Proxy

While getting a new workstation is usually nice, reinstalling all your softwares and settings is definitely not the most pleasant thing that comes to my mind. One of the factors that can contribute the most to making the process even less pleasant is working around the corporate proxy.

Many applications live on the assumption that nobody uses proxy servers, thus making online repositories inaccessible for new installations and for automatic updates.

Unfortunately, PsGallery is no exception.

If you run Get-PSRepository on a vanilla installation of Windows 10 behind a corporate proxy, you will get a warning message:

WARNING: Unable to find module repositories.

After unleashing my Google-Fu, I learned that I had to run the following command to recover the missing PsRepository:

Register-PSRepository -Default -Verbose

The command works without complaining, with just a warning suggesting that something might have gone wrong:

VERBOSE: Performing the operation "Register Module Repository." on target "Module Repository 'PSGallery' () in provider 'PowerShellGet'.".

Again, running Get-PSRepository returns an empty result set and the usual warning:

WARNING: Unable to find module repositories.

The problem here is that the cmdlet Register-PsRepository assumes that you can connect directly to the internet, without using a proxy, so it tries to do so, fails to connect and does not throw a meaningful error messsage. Thank you, Register-PsRepository, much appreciated!

In order to fix it, you need to configure your default proxy settings in your powershell profile. Start powershell and run the following:

notepad $PROFILE

This will start notepad and open your powershell profile. If the file doesn’t exist, Notepad will prompt you to create it.

Add these lines to the profile script:

[]::defaultwebproxy = new-object'http://YourProxyHostNameGoesHere:ProxyPortGoesHere')
[]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[]::defaultwebproxy.BypassProxyOnLocal = $true

Save, close and restart powershell (or execute the profile script with iex $PROFILE).

Now, you can register the default PsRepository with this command:

Register-PSRepository -Default

If you query the registered repositories, you will now see the default PsRepository:


Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted  




Posted on December 19, 2017, in PowerShell and tagged . Bookmark the permalink. 17 Comments.

  1. Great article, I just spent all morning trying to install the AzureAD module on a Windows 2016 server. This has resolved it as I am going through a proxy server.

  2. Kojo Obeng Antwi

    Thank you so much. I have been chasing my tail until I found your article. It worked like a charm.

  3. Awesome! Many thanks!

  4. Many thanks!

  5. Awesome guide. It worked to me.

  6. You are amazing! Worked perfectly.
    Thank you.

  7. I believe this was the final solution to my 12 step problem to get NUGET working behind a firewall 😉 Thanks!

  8. back of the net!!

  9. Thanks for the article. It saved my day.

  10. How do i know what my proxy settings are? ON local systems i don’t have any enabled, but i am on a corporate AD system which could be using one.. is there any way to tell what it is?

    • This line of powershell tells you what the proxy settings are on the current machine:

      (Get-ItemProperty -Path “Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”).ProxyServer

      You could run it on the target machine to see what it gives.
      Hope this helps

  11. thank you so so much, I wasted half a morning on this

  12. OMG! I was looking soooooooo long for this solution, finally I found this site! 😀

  13. Thanks, Was banging my head on this one for a while. I knew it was the web proxy!

  1. Pingback: Offline WIM Servicing – WIP – ConfigMgrUK

Leave a Reply to Steve Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: