13

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.

jscott
  • 24,484
  • 8
  • 79
  • 100
Vic
  • 133
  • 1
  • 1
  • 5
  • cross-site duplicate: [Why can “find” not be used in PowerShell](https://superuser.com/q/1208964/241386). It may be better to use `select-string` in powershell – phuclv Apr 02 '18 at 01: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. – Eric Hepperle - CodeSlayer2010 Mar 24 '21 at 19:57

1 Answers1

20

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"
jscott
  • 24,484
  • 8
  • 79
  • 100