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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With