Skip to content

Commit b2f217f

Browse files
Invoke-TlsWebRequest - Auto-detect system proxy (#10310)
1 parent 392fc9d commit b2f217f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

private/configurations/settings/commands.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ Set-DbatoolsConfig -FullName 'commands.test-elevationrequirement.disable' -Value
1919

2020
# Get-DbaDbTable
2121
Set-DbatoolsConfig -FullName 'commands.get-dbadbtable.clearandinitialize' -Value $false -Initialize -Validation bool -Description "Controls whether Get-DbaDbTable uses ClearAndInitialize to load all table properties in one optimized query. Set to true to enable the optimization, which loads all properties in a single query but clears already loaded SMO properties. Keep at false when reusing SMO objects across multiple calls (e.g. in Copy-DbaDbTableData)."
22+
23+
# Invoke-TlsWebRequest
24+
Set-DbatoolsConfig -FullName 'commands.invoke-tlswebrequest.disableautoproxy' -Value $false -Initialize -Validation bool -Description "Disable automatic system proxy detection in Invoke-TlsWebRequest. Set to true to skip auto-detection of the system proxy (useful if auto-detection causes issues in your environment)."

private/functions/Invoke-TlsWebRequest.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ function Invoke-TlsWebRequest {
1414
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor $_
1515
}
1616

17+
# Auto-detect system proxy if not already configured and not opted out
18+
if (-not (Get-DbatoolsConfigValue -FullName "commands.invoke-tlswebrequest.disableautoproxy") -and -not [System.Net.WebRequest]::DefaultWebProxy.Address) {
19+
$systemProxy = [System.Net.WebRequest]::GetSystemWebProxy()
20+
if ($systemProxy) {
21+
[System.Net.WebRequest]::DefaultWebProxy = $systemProxy
22+
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
23+
}
24+
}
25+
1726
# IWR is crazy slow for large downloads
1827
$currentProgressPref = $ProgressPreference
19-
$ProgressPreference = 'SilentlyContinue'
28+
$ProgressPreference = "SilentlyContinue"
2029
Invoke-WebRequest @Args
2130
$ProgressPreference = $currentProgressPref
2231

0 commit comments

Comments
 (0)