That error happened because PowerShell's
$_
and the try/catch block were sent inside a command string in the wrong shell/with the wrong quoting — Windows interpreted the
$_.Exception.Message
text literally (or you were already inside an interactive nslookup prompt). The easiest fix is: open PowerShell (Admin) and run the commands directly (no need to call
powershell -Command
from cmd). Below are exact, copy‑ready PowerShell commands you can run (run them from an elevated PowerShell window).
If you want the quick tests (recommended first)
Open PowerShell as Administrator and run these three commands one at a time:
1) Test HTTP by IP (bypasses DNS)
Try { (Invoke-WebRequest -Uri '
http://216.58.214.14' -UseBasicParsing -TimeoutSec 8).StatusCode } Catch { $_.Exception.Message }
2) Test HTTPS by name
Try { (Invoke-WebRequest -Uri '
https://www.google.com' -UseBasicParsing -TimeoutSec 8).StatusCode } Catch { $_.Exception.Message }
3) Check WinHTTP proxy and DNS Client
netsh winhttp show proxy
sc query dnscache
Tell me the exact output for each (or take a photo of the window). If HTTP-by-IP succeeds but HTTPS/name fails, we focus on WinHTTP/proxy or a local DNS/agent. If they both fail, we look at firewall/AV or stack corruption.
If you want the full diagnostic file (if you can't paste results)
Run this entire PowerShell block (Admin). It gathers everything to C:\Temp\webdiag.txt and opens it in Notepad:
$Out='C:\Temp\webdiag.txt'
New-Item -Path C:\Temp -ItemType Directory -Force | Out-Null
"
n==== date/time ====
n" | Out-File $Out
"==== ipconfig /all ====" | Out-File $Out -Append
ipconfig /all | Out-File $Out -Append
"==== Get-NetAdapter ====" | Out-File $Out -Append
Get-NetAdapter | Format-Table -Auto | Out-File $Out -Append
"==== Get-DnsClientServerAddress (IPv4) ====" | Out-File $Out -Append
Get-DnsClientServerAddress -AddressFamily IPv4 | Format-List | Out-File $Out -Append
"==== netsh winhttp show proxy ====" | Out-File $Out -Append
netsh winhttp show proxy | Out-File $Out -Append
"==== sc query dnscache ====" | Out-File $Out -Append
sc query dnscache | Out-File $Out -Append
"==== nslookup google.com 8.8.8.8 ====" | Out-File $Out -Append
nslookup google.com 8.8.8.8 | Out-File $Out -Append
"==== nslookup google.com (default) ====" | Out-File $Out -Append
nslookup google.com | Out-File $Out -Append
"==== Invoke-WebRequest by IP (http) ====" | Out-File $Out -Append
Try { (Invoke-WebRequest -Uri '
http://216.58.214.14' -UseBasicParsing -TimeoutSec 8).StatusCode | Out-File $Out -Append } Catch { ('ERROR: ' + $
.Exception.Message) | Out-File $Out -Append }
"==== Invoke-WebRequest by name (https) ====" | Out-File $Out -Append
Try { (Invoke-WebRequest -Uri 'https://www.google.com' -UseBasicParsing -TimeoutSec 8).StatusCode | Out-File $Out -Append } Catch { ('ERROR: ' + $.Exception.Message) | Out-File $Out -Append }
"==== tracert google.com ====" | Out-File $Out -Append
tracert -d -h 8 google.com | Out-File $Out -Append
"==== netstat -rn ====" | Out-File $Out -Append
netstat -rn | Out-File $Out -Append
notepad $Out
After Notepad opens you can copy the file to a USB stick or photograph it and upload it from another device.
Why this fixes the quoting error
- Running the PowerShell commands directly avoids the messy escaping you need when embedding
$
and braces inside a quoted -Command
string called from cmd.exe. Running them in PowerShell (Admin) runs the try/catch and $_
variable correctly.
If you prefer to stick to cmd.exe
Use this exact one‑line (cmd) — note the backslashes for escaping the
$
inside double quotes:
powershell -NoProfile -Command "Try { (Invoke-WebRequest -Uri '
http://216.58.214.14' -UseBasicParsing -TimeoutSec 8).StatusCode } Catch { `$_.Exception.Message }"
But I strongly recommend opening PowerShell (Admin) and running the simpler forms above instead.
Next step
Run the three quick PowerShell tests I gave at the top, tell me their outputs (or upload C:\Temp\webdiag.txt). I’ll read them and give the exact fix (usually one of: reset WinHTTP proxy, stop/uninstall a DNS proxy/VPN agent, reset Winsock, or reconfigure the adapter DNS properly). Reference: standard Windows network diagnostic steps and network reset/Winsock fixes.
Which do you want to run now — the three quick tests or the full diagnostic script?