Chris D.
Chris D.

Reputation: 21

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

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.

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

Upvotes: 2

Views: 1056

Answers (1)

TheMadTechnician
TheMadTechnician

Reputation: 36277

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"
}

Upvotes: 1

Related Questions