Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » Select-String

Select-String - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »


Search through strings or files for patterns

Select-String [-pattern] string[] [-text string]
              {-inputObject psobject | [-path] string[]}
                 [-include string[]] [-exclude string[]] [-simpleMatch] 
                    [-caseSensitive] [-quiet] [-list] [CommonParameters]

-pattern string
       The string or regular expression to match.

   -text string
       Literal text to match against the value of -Pattern.
   -Path path
       Strings or files to match against, wildcards are allowed.

   -include string
       Include only the specified items from the Path. e.g. "May*"
       this only works when the path includes a wildcard character.
   -exclude string
       Omit the specified items from the Path e.g. "*SS64*"
       this only works when the path includes a wildcard character.

        Use a simple match, rather than a regular expression match

       Make the matches case sensitive.
       Suppress most of the output from Select-String.  
       When specified, only a boolean value is passed along the pipeline. 
       TRUE = a match was found, otherwise FALSE.
       Only return info. about the first match from each input file.
   -inputObject psobject
       Accept an object as input to Select-String. Enter a variable,
       command or expression that gets the objects.

      -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Perform a case sensitive matching of literal strings:

PS C:\>"Hello","HELLO" | select-string -pattern "HELLO" -casesensitive

Search through all files with the .xml file extension in the current directory and displays the lines in those files that include the case sensitive string "Princess":

PS C:\>select-string -path *.xml -pattern "Princess" -casesensitive

Retrieve the last 100 events from the application event log and filter to show only those containing the message string "failed":

PS C:\>$events = get-eventlog -logname application -newest 100
$events | select-string -inputobject {$_.message} -pattern "failed"