I'm attempting to parse the output of netsh winhttp show proxy to ensure the correct proxy settings have been applied with my script. To start, this is the expected output of the command:
Current WinHTTP proxy settings:
Proxy Server(s) : proxy.website.com:8080
Bypass List : *.example1.com;*.sample-site.com;
Below is a cut down version of what I'm doing. The if statement is evaluating to false when it should be true (I know the proxy settings are correct before running). I'm suspecting there's an issue with how I'm utilizing multiple wildcards with the -like operator, as evaluating only $ProxyServer or $BypassListEscaped on their own work, but I'm not sure. Any ideas? Thanks!
$NetshOutput = (netsh winhttp show proxy)
$ProxyServer = "proxy.website.com:8080"
$ProxyBypass = "*.example1.com;*.sample-site.com;"
$BypassListEscaped = $ProxyBypass.Replace("*", "``*").Replace("`"", "")
if ($NetshOutput -like "*$ProxyServer*$BypassListEscaped*"){
Write-Host "correct"
}else{
Write-Host "incorrect"
}
Output from
netshcommand is an array of strings, you need to convert that array into a single string before your comparison. You can also useWildcardPattern.Escapemethod for escaping wildcard characters.