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. 34 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!


    Thanks buddy, this helped a lot. it was a headache for a while.

  15. Thanks mate for sharing this, now raises the questions for the users who are restricted behind the Internet terminal server and not the proxy server, how are they able to get their powershell configured for getting around the terminal server ?

    • I’m sorry,I don’t even know what internet terminal server is…

      • Well, in some IT organizations to consolidate the internal network security (Usaully applied for IT Admins) another layer, shields and prevents the internal clients from directly accessing the proxy server. Instead these clients establish a connection to the Terminal Server (The server is used for application or Internet distribution among internal clients) through the RDP and this Terminal Server is in its turn placed behind the proxy server. Here is the exact scenarion which i am dealing with 😉 . Now i am at the point of finding a way to fool the Terminal server in the first place then take care of the proxy server.. Anyway thanks for the response my friend

  16. Thanks worked like a charm!

  17. At last, an article I can understand! Thanks for explaining it clearly and concisely.
    No thanks to Microsoft for making it so hard (and difficult to troubleshoot).

  18. You need to note:

    After “notepad $PROFILE” you have to close all Powershell Editors or windows and start as administrator the powershell editor again!

    …don’t forget save your ps – scripts before!

  19. This Article should be the first result on Google search

  20. Thank you!!

  21. Thank you so much guy for sharing this !!! Sharing is caring 🙂

  22. If the above doesn’t work – try running this. MS Disabled TLS1.0 & 1.1 support to their gallery earlier in the year

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    May also need to to turn off FIPS Cryptography using the Local Policies

    Can reenable after registering module

  23. Thanks so much for sharing this! I’m new to PS and was tearing my hair out trying to figure out why I was getting nothing but angry red errors trying to to do anything regarding repositories from a server sitting behind a proxy.

  24. Awesome stuff, I have been working on this for a while and this solved my issue downloading Powershell modules within our corporate environment.

  25. it worked super 🙂

  26. Thank you, since I learned something new, thought I’d share.
    You do not need to restart powershell, instead call . $profile # to reload the profile script

  1. Pingback: Offline WIM Servicing – WIP – ConfigMgrUK

  2. Pingback: SCOMHelper PowerShell Module – A SCOM Admin’s Best Friend - The Monitoring Guys

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: