Getting Web Proxy Settings
We have a lab of hosts that have proxy exclusion lists set at various times in the lifecycle of the lab, so they have slightly varying values.
We'll build on the REG_BINARY to [string] trick with this:
function Get-WinHttpProxy {
param ( [string[]]$computer = '.' );
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer);
$subKey= "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" -replace '\\', '\\';
$regKey= $reg.OpenSubKey($subkey);
$proxyServer = $exclusionList = $null;
if ($regKey) {
$data = $regKey.GetValue('WinHttpSettings');
if (!$data -or $data.Count -le 16) {
Write-Warning "$computer insufficent proxy data returned";
} else {
$data1 = $data[16 .. ($data.Count-1)];
$firstNull = [array]::IndexOf($data1, [byte]0);
if ($firstNull -le 1) {
Write-Warning "$computer incorrect prxy data returned";
} else {
$proxyServer = [string]::Join("",($data1[0 .. ($firstNull-2)]| % {[char][int]$_}));
if ($data1.Count -lt ($firstNull+3)) {
} else {
$exclusionList = [string]::Join("",($data1[($firstNull+3) .. ($data1.Count-1)]| % {[char][int]$_}));
}
}
}
}
$computer | Select-Object -Property @{
name = 'Computer';
expression = { $computer; }
}, @{
name = 'ProxyServer';
expression = { $proxyServer; }
}, @{
name = 'ExclusionList';
expression = { $exclusionList; }
};
}