dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.48k stars 805 forks source link

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

Open potatoqualitee opened 5 years ago

potatoqualitee commented 5 years ago

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
    }
wsmelton commented 5 years ago

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

niphlod commented 5 years ago

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 ?

potatoqualitee commented 5 years ago

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

niphlod commented 5 years ago

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

potatoqualitee commented 3 years ago

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