invoke-WebRequest and a proxy that refuses to die in Powershell 5.1

879 Views Asked by At

I have a Windows Server 2019 instance that used to have a proxy server configured in its proxy setting but has since been disabled from Proxy Settings -> Proxy

If I run the powershell 5.1 command:

Invoke-WebRequest https://<LOCALURL>

then i'm still directed though the previously configured proxy and my request is denied. If I run the same command though powershell 7.2 then it works as expected.

I've made the following changes to try to rid any residual proxy configurations but nothing has worked.

  • Disabled MigrateProxy: hcu\software\microsoft\windows\currentversion\internet settings\MigrateProxy: Changed from 1 to 0
  • netsh winhttp import proxy source=ie
  • netsh winhttp reset proxy
  • Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Type DWord -Value 0
  • Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -Type String -Value ""
  • Searched and combed for proxy values in the registry
  • Restarted numerous times

Where is powershell 5.1 still pulling the removed proxy configuration from??

1

There are 1 best solutions below

2
On

You can make sure that you don't have anything in your DefaultConnectionSettings, which is a byte array and has to be parsed, but you can check that for the current user and local machine keys, and that may be causing you grief:

$KeyPath = '\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections'
$PropertyName = 'DefaultConnectionSettings'

$LMBytes = Get-ItemPropertyValue -Path "HKLM:$KeyPath" -Name $PropertyName
$LMProxyStringLength = $LMBytes[12]
If(!$LMProxyStringLength){Write-Host "No proxy set for Local Machine key"}else{
    $LMProxyString = ($LMBytes[16..(16+$LMBytes[12])]|%{[char]$_}) -join ''
    Write-Warning "Local Machine proxy set to $LMProxyString"
}

$CUBytes = Get-ItemPropertyValue -Path "HKCU:$KeyPath" -Name $PropertyName
$CUProxyStringLength = $CUBytes[12]
If(!$CUProxyStringLength){Write-Host "No proxy set for Current User key"}else{
    $CUProxyString = ($CUBytes[16..(16+$CUBytes[12])]|%{[char]$_}) -join ''
    Write-Warning "Local Machine proxy set to $CUProxyString"
}