dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Discussion: Autodetect Proxy Server and set in Invoke-TlsWebRequest?

Open potatoqualitee opened this issue 6 years ago • 5 comments

This is what I'm doing in another module

$proxy = (Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings").ProxyServer

    if ($proxy -and -not ([System.Net.Webrequest]::DefaultWebProxy).Address) {
        [System.Net.Webrequest]::DefaultWebProxy = New-object System.Net.WebProxy $proxy
        [System.Net.Webrequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
    }

potatoqualitee avatar Jul 10 '19 12:07 potatoqualitee

Could you just use [System.Net.WebRequest]::GetSystemWebproxy() to get it instead of looking at the regkey?

https://docs.microsoft.com/en-us/dotnet/api/system.net.webrequest.getsystemwebproxy?view=netframework-4.8#System_Net_WebRequest_GetSystemWebProxy

wsmelton avatar Jul 10 '19 23:07 wsmelton

this would probably work just for "fixed" proxies. Evaluating, e.g., a PAC file would be .... a better fix, if .net has already a method for it ?

niphlod avatar Jul 15 '19 22:07 niphlod

thx wassa pac and would this negatively impact users or just not cover enough of them?

potatoqualitee avatar Jul 15 '19 23:07 potatoqualitee

https://en.wikipedia.org/wiki/Proxy_auto-config

niphlod avatar Jul 16 '19 00:07 niphlod

Should we do [System.Net.WebRequest]::GetSystemWebproxy() with a config option to disable?

potatoqualitee avatar Jul 30 '21 11:07 potatoqualitee