> ## Content Index
> Fetch the complete content index at: https://www.techielass.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to use PowerShell's Grep
- URL: https://www.techielass.com/how-to-use-powershells-grep/
- Published: 2021-08-17T10:15:00.000Z
- Updated: 2023-03-02T17:30:27.000Z
- Description: Join me as I look at how you can use grep within PowerShell
- Author: Sarah Lean
- Tags: PowerShell, Tip, Windows Terminal, Grep, Windows 10, Windows 11

One command that is prominent in Linux system administrators' toolbox is grep. This tool's core ability is to search plain text for a RegEx pattern. Grep can search files in a given directory.

In the PowerShell world, do we have that command? Well, kind of.  
  
**Select-String** can help search for text or text patterns in input strings and files. It's very similar to grep or even findstr in Windows.  
  
There are three ways you can use Select-String: pipe in quoted text, use text stored in a variable or use the Path parameter to specify files to search for the text in.

**Examples**

We can search for text within files with the command:

```PowerShell
Select-String -Path "*.csv" -Pattern "Rachel"

```

![Select-String Result](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2021/07/selectstring.PNG)

Select-String result

The result of this Select-String search is finding the name Rachel within the file twice.

You may want to find an event within a Windows Event Log, and rather than sit and search through it, you can use the Select-String command.

```PowerShell
#Let's get the 50 most recent events from the System Log and store the information in the variable events

$Events = Get-WinEvent -Log System -MaxEvents 50

#We send the variable into the Select-String pipeline and it searches for any events that have delete operations in them

$Events | Select-String -InputObject {$_.message} -Pattern 'Delete'

```

![Searching Events Logs with Select-String](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2021/07/delete.PNG)

Searching Events Logs with Select-String

So the above command collects the last 50 events from the System log, and then, using Select-String, we look for any events that have the string delete in them. 

I hope this has given you some inspiration on how to use grep within PowerShell! 👍