2

I want to create a Powershell script to automatically tick the proxy settings "Automatically detect settings" and "Use automatic configuration script" as : Proxy Settings

So I found some tips, I am able to tick "Use automatic configuration script" with my proxy address with :

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name AutoConfigURL -value 'proxy address'

And I am able to tick "Automatically detect settings" with

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections'
$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings
$data[8] = 9
Set-ItemProperty -Path $key -Name DefaultConnectionSettings -Value $data

But If I try both like to put the two codes on the same script it doesn't work and only "Use automatic configuration script" is ticked.

I also saw that I can use the value 0d from : Source.

But when I tried that the output is "Error: Input string was not in a correct format."

Do you have any Idea on how I can do this ? Thank you.

4
  • Try [byte[]]$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings and Set-ItemProperty -Path $key -Name DefaultConnectionSettings -Value $data -PropertyType Binary Commented Mar 12, 2020 at 12:32
  • So i tried your lines putting 0d as value for $data[8] But I still get the same error : Error: "Input string was not in a correct format." Any other Ideas ? thanks Commented Mar 13, 2020 at 11:35
  • Then how do you set the value of byte[8] exactly? I think the error you show refers to that part. Use $data[8] = 0x0d or $data[8] = 13 Commented Mar 13, 2020 at 11:43
  • Hi Theo, Thanks for that it worked for me with $data[8] = 0x0d Commented Mar 18, 2020 at 15:59

1 Answer 1

3
[byte[]]$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings

change to

[byte[]]$data = (Get-ItemProperty -Path $key).DefaultConnectionSettings

Overall, this is wonderful, great job Theo, thank you for sharing.

Todd

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

Comments

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.