6

My proxy is configured using the "automatic configuration script" option in the LAN settings dialog in IE. In order to toggle this settings I have written the following powershell script:

$proxyScript = 'http://example.com/files/wish.pac'
$debug = $TRUE
$currentValue = Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL -ErrorAction SilentlyContinue

if($debug)
{
    Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}

if([string]::IsNullOrEmpty($currentValue))
{
    Write-Host "Proxy-AutoConfigURL is actually disabled"
    Set-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL -value $proxyScript
    Write-Host "Proxy-AutoConfigURL is enabled: " + $proxyScript
}
else
{
    Write-Host "Proxy-AutoConfigURL is actually enabled"
    Remove-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL
    Write-Host "Proxy-AutoConfigURL is disabled."
}

if($debug)
{
    Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}

The script seems to work as the values have changed in IE's LAN settings dialog after having executed the script. But they seem not to be applied in IE and other applications using the system wide settings. Only when I click on the OK button in the LAN settings dialog the updated values get applied.

Is there a way to apply the changed settings automatically using powershell?

2
  • Are you sure the ProxyEnable-value is 0? Commented Apr 14, 2015 at 10:54
  • works great, thanks! Commented Jun 17, 2016 at 12:47

1 Answer 1

7

You need to notify the system about update. Check out my proxy module which doesn't handle autoconfig but the principle is the same

https://github.com/majkinetor/posh/blob/master/MM_Network/Update-Proxy.ps1

See refresh-system function.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for this answer, your link was not working anymore, I fixed it.
Thanks, I changed module name later :)
What (if any) might be the disadvantages of calling refresh-system e.g. each 5 minutes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.