siom
siom

Reputation: 1807

How to apply changed proxy settings (AutoConfigURL) with powershell

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?

Upvotes: 5

Views: 11905

Answers (1)

majkinetor
majkinetor

Reputation: 9036

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.

Upvotes: 7

Related Questions