Discussion: Autodetect Proxy Server and set in Invoke-TlsWebRequest?
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
}
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
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 ?
thx wassa pac and would this negatively impact users or just not cover enough of them?
https://en.wikipedia.org/wiki/Proxy_auto-config
Should we do [System.Net.WebRequest]::GetSystemWebproxy() with a config option to disable?