Configuring PowerShell to work behind an authenticated proxy server

PowerShell

How to connect PowerShell to the internet with authenticated proxy servers. PowerShell won’t update help, or let you connect to online repositories, without configuring it to work with your corporate web proxy proxies. There are a few options to configure a proxy, however only one of them will work with a proxy requiring authentication.

If you try and use an online command such as update-help, you will get an error like this:


PS C:\WINDOWS\system32> update-help
update-help : Failed to update Help for the module(s) 'ActiveDirectory, AppBackgroundTask, AppLocker, AppvClient,
Appx, AssignedAccess, BestPractices, BitLocker, BitsTransfer, BranchCache, CimCmdlets, ClusterAwareUpdating, ….Unable to
connect to Help content. The server on which Help content is stored might not be available. Verify that the server is
available, or wait until the server is back online, and then try the command again.

At line:1 char:1
+ update-help
+ ~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
+ FullyQualifiedErrorId : UnableToConnect,Microsoft.PowerShell.Commands.UpdateHelpCommand

  • For individual users, you can just set the system Internet settings
  • For system-wide settings, use the following command e.g. netsh winhttp set proxy 192.168.5.6:8118 bypass-list=”*internal.cloudrun.uk”

Whilst these will work for unauthenticated proxies, there is some more work to do if your proxy requires authentication.

To fix this, you need to configure your proxy settings in your PowerShell profile as follows (note that this requires local administrator rights):

  • Open an administrator-level PowerShell command prompt
  • Run the following command to register the PSGallery Repository
  • Edit your profile:

notepad $PROFILE

Note: it will prompt you to create this if it does not exist. Then add the following lines, modifying as you see fit for your environment:


[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://proxyname:port')

[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Restart PowerShell. Note that you will need to have scripts enabled in order to load the profile.

Now, you can run update-help again and it should have no issues.

You can also now connect to Office365 using PowerShell, see https://cloudrun.co.uk/office365/connecting-to-office-365-using-powershell/

Posted in Office 365, PowerShell

Related Posts

1 Comment

  1. Pingback:Connecting to Office 365 using PowerShell - Cloudrun

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.