Created
October 1, 2017 03:43
-
-
Save PlagueHO/0ca7312595a60eae4f4a360f2f5badef to your computer and use it in GitHub Desktop.
Create a Byte Array for setting Windows proxy machine level settings in the registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Convert the proxy settings parameters to a Byte Array that | |
can be used to populate the DefaultConnectionSettings and | |
SavedLegacySettings registry settings in the registry key | |
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections | |
.PARAMETER EnableAutoDetection | |
Enable automatic detection of the proxy settings. Defaults | |
to 'False'. | |
.PARAMETER EnableAutoConfiguration | |
Use automatic configuration script for specifying proxy | |
settings. Defaults to 'False'. | |
.PARAMETER EnableManualProxy | |
Use manual proxy server settings. Defaults to 'False'. | |
.PARAMETER AutoConfigURL | |
The URL of the automatic configuration script to specify | |
the proxy settings. Should be specified if 'EnableAutoConfiguration' | |
is 'True'. | |
.PARAMETER ProxyServer | |
The address and port of the manual proxy server to use. | |
Should be specified if 'EnableManualProxy' is 'True'. | |
.PARAMETER ProxyServerExceptions | |
Bypass proxy server for addresses starting with addresses | |
in this list. | |
.PARAMETER ProxyServerBypassLocal | |
Bypass proxy server for local addresses. Defaults to 'False'. | |
#> | |
function ConvertTo-ProxySettingsBinary | |
{ | |
[CmdletBinding()] | |
[OutputType([System.Byte[]])] | |
param | |
( | |
[Parameter()] | |
[System.Boolean] | |
$EnableAutoDetection = $false, | |
[Parameter()] | |
[System.Boolean] | |
$EnableAutoConfiguration = $false, | |
[Parameter()] | |
[System.Boolean] | |
$EnableManualProxy = $false, | |
[Parameter()] | |
[System.String] | |
$AutoConfigURL, | |
[Parameter()] | |
[System.String] | |
$ProxyServer, | |
[Parameter()] | |
[System.String[]] | |
$ProxyServerExceptions = @(), | |
[Parameter()] | |
[System.Boolean] | |
$ProxyServerBypassLocal = $false | |
) | |
[System.Byte[]] $proxySettings = @(0x46, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0) | |
if ($EnableManualProxy) | |
{ | |
$proxySettings[8] = $proxySettings[8] + 2 | |
} | |
if ($EnableAutoConfiguration) | |
{ | |
$proxySettings[8] = $proxySettings[8] + 4 | |
} | |
if ($EnableAutoDetection) | |
{ | |
$proxySettings[8] = $proxySettings[8] + 8 | |
} | |
if ($PSBoundParameters.ContainsKey('ProxyServer')) | |
{ | |
$proxySettings += @($ProxyServer.Length, 0x0, 0x0, 0x0) | |
$proxySettings += [Byte[]][Char[]] $ProxyServer | |
} | |
else | |
{ | |
$proxySettings += @(0x0, 0x0, 0x0, 0x0) | |
} | |
if ($ProxyServerBypassLocal -eq $true) | |
{ | |
$ProxyServerExceptions += @('<local>') | |
} | |
if ($ProxyServerExceptions.Count -gt 0) | |
{ | |
$ProxyServerExceptionsString = $ProxyServerExceptions -join ';' | |
$proxySettings += @($ProxyServerExceptionsString.Length, 0x0, 0x0, 0x0) | |
$proxySettings += [Byte[]][Char[]] $ProxyServerExceptionsString | |
} | |
else | |
{ | |
$proxySettings += @(0x0, 0x0, 0x0, 0x0) | |
} | |
if ($PSBoundParameters.ContainsKey('AutoConfigURL')) | |
{ | |
$proxySettings += @($AutoConfigURL.Length, 0x0, 0x0, 0x0) | |
$proxySettings += [Byte[]][Char[]] $AutoConfigURL | |
} | |
$proxySettings += @(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) | |
$proxySettings += @(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) | |
return [System.Byte[]] $proxySettings | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment