using select-string

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 2 years, 2 months ago.

  • Author
    Posts
  • #19118
    Profile photo of Garegin Asatryan
    Garegin Asatryan
    Participant

    As far as I understand select-string is the closest analogue to grep in powershell (someone should tell Snover to add it as an alias 🙂 ). I try to just "search through the text" of the command output, but sometimes I get weird results. for example, it never works for the output of invoke-webrequest. I am doing something wrong?

  • #19120
    Profile photo of Ondrej Zilinec
    Ondrej Zilinec
    Participant

    alias "grep" would be nice 🙂

    Can you, specify what problem are you having with Select-String when used with Invoke-WebRequest?

  • #19121
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Without seeing any specifics, it's hard to say what your problem is. However, I can offer a guess. The -Pattern you pass to Select-String, by default, is a regular expression. If you're not expecting this, you may be using special regex characters that need to be escaped in order to work properly. If you don't want to do a regex pattern, just add the -SimpleMatch switch to your call to Select-String, and the pattern becomes a literal string.

You must be logged in to reply to this topic.