16

Just curious, why does this happen? If I run:

netstat -an | find "443"

into a command prompt, "443" connections are displayed ok. If I run the same command in a PowerShell console or ISE, I get the error "FIND: Parameter format not correct". Is netstat output not being piped properly to find in PS?

Note: If I run netstat -an | findstr "443" or netstat -an | select-string "443" in PS those work as expected.

2
  • cross-site duplicate: Why can “find” not be used in PowerShell. It may be better to use select-string in powershell Commented Apr 2, 2018 at 1:23
  • @phuclv I just came from that post. Not a duplicate because although the question may be in the same "family", it isn't the same. Nor is it substantially similar. Nor does the linked question offer any really useful solutions. This question is different and offers different answers that should be of value to many. I certainly know that other question didn't help me whereas this one did. Commented Mar 24, 2021 at 19:57

1 Answer 1

24

PowerShell evaluates the content within double quotes to perform any variable expansion, sub-expressions, etc, then it discards those double quotes. What PowerShell returns from "443" is literally 443 (note the missing quotes). FIND.EXE requires the search string enclosed with double quotes.

If you want to prevent PowerShell from stripping the double quotes use the grave accent (`) to escape them.

netstat -a -n | find `"443`" 

You may also use the --% parameter to perform the escape. Requires PowerShell 3+.

nestat -a -n | find --% "443" 
3
  • I wonder why findstr.exe works without escaping? Commented Mar 1, 2016 at 16:45
  • 3
    @Vic The findstr utility does not require double quotes in the /C string parameter: findstr /C:somestring somefile works as does findstr /C:"somestring" somefile. For FIND, the double quotes are required present. Commented Mar 1, 2016 at 16:48
  • Works in 2021! I ran this successfully: netstat -ano | find --% "33" Commented Mar 24, 2021 at 20:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.