Bypass Proxy for All Web Requests in Powershell Core

I have a work computer running on Windows in a corporate environment with an authenticating proxy server for outgoing connections to the internet. I don't know how it's configured, but many tools fail to connect, mainly that type like npm (packages in the Atom editor), NuGet, PowerShellGet, etc. I even had to configure my browser (Vivaldi) to use the direct connection, because I couldn't, for example, sign in on some websites, even though it was working in MS Edge.

The HTTP error is usually (407) Proxy Authentication Required.

The system-wide proxy server in Windows is being configured by some periodically executed script and I cannot do anything about it.

The solution, or rather a workaround, is to individually configure all applications that have issues with connections to bypass the proxy (use the direct connection to the internet). I have managed to do that for almost everything I needed, but I didn't succeed with Powershell Core so far.

BTW I'm not sure what's the point of that proxy when you can simply bypass it, it's just making regular work harder on that computer and it's wasting my time and company's money.

So far, I have found out the following.

PowerShellGet's Find-Module fails with the error:

Unable to resolve package source '

A simple web request fails with the error "Cache Access Denied":

Invoke-WebRequest 

But succeeds when it's forced to bypass the proxy:

Invoke-WebRequest  -NoProxy

netsh winhttp show proxy says "Direct access (no proxy server).", but the following command returns an actual proxy:

([System.Net.WebRequest]::GetSystemWebproxy()).GetProxy("")

Also, the following command returns false:

([System.Net.WebRequest]::GetSystemWebproxy()).IsBypassed("")

I have done quite extensive research and found out that it should be possible to configure WebRequest to use the direct connection by setting the default proxy to null, but it didn't help:

[System.Net.WebRequest]::DefaultWebProxy = $null

I would appreciate if anyone has any other idea.

Update

I have found out that I can actually use my domain account to authenticate on the proxy server:

Invoke-WebRequest  -ProxyUseDefaultCredentials -Proxy 

So that would be an alternative to the proxy bypass configuration. I just don't know how to set credentials for all requests made by Powershell. I don't understand why the Windows system proxy is not configured to use my account to authenticate.

I have tried to configure WebRequest::DefaultWebProxy to use the proxy server and authenticate on it using my domain account credentials, but it didn't work:

[System.Net.WebRequest]::DefaultWebProxy 
    = New-Object System.Net.WebProxy(')
[System.Net.WebRequest]::DefaultWebProxy.Credentials
    = [System.Net.CredentialCache]::DefaultNetworkCredentials
3

Finally, after several hours of researching and messing around, I was able to solve my issue thanks to this GitHub issue comment!

I don't know the background, but it looks like Powershell Core is actually using System.Net.Http.HttpClient rather than System.Net.WebRequest for making web requests.

When I have learned that, it was quite easy to configure HttpClient's default proxy.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.