As a PowerShell administrator, I mostly worked with the PowerShell Select-String cmdlet. So, I thought to show you 10 real examples of Select-String in PowerShell.
Example 1: Basic Text Search in a File
The most straightforward use of Select-String in PowerShell is to search for a specific text pattern in a file.
Select-String -Pattern "Error" -Path "C:\Logs\ApplicationLogs.txt"
This command searches for the word “Error” in the ApplicationLogs.txt file and returns all matching lines. I use this daily when troubleshooting application issues in our Chicago data center, as it quickly identifies error messages without having to scroll through thousands of log entries.
Here is the output in the screenshot below:

For the above example, I am using the following text file.
[2025-06-24 08:15:32] INFO: Application started successfully
[2025-06-24 08:16:45] INFO: User johndoe@example.com logged in from 192.168.1.105
[2025-06-24 08:17:22] WARNING: High memory usage detected (85%)
[2025-06-24 08:22:14] INFO: Database connection established
[2025-06-24 08:25:33] ERROR: Failed to process transaction #TR-29584 - Timeout
[2025-06-24 08:25:34] DEBUG: Attempting transaction retry
[2025-06-24 08:26:01] ERROR: Database query execution failed with error code DB-5012
[2025-06-24 08:26:02] DEBUG: Stack trace: System.Data.SqlClient.SqlException: Timeout expired
[2025-06-24 08:30:45] INFO: Scheduled maintenance starting
[2025-06-24 08:32:19] WARNING: API response time exceeding threshold (2500ms)
[2025-06-24 08:40:11] INFO: Backup process initiated
[2025-06-24 08:45:02] ERROR: Permission denied accessing file C:\data\reports\monthly.xlsx
[2025-06-24 08:45:22] INFO: User johndoe@example.com logged out
[2025-06-24 09:01:13] INFO: New user registration: sarahsmith@example.com
[2025-06-24 09:05:44] WARNING: CPU utilization spike detected
[2025-06-24 09:10:22] INFO: Configuration updated
[2025-06-24 09:15:56] ERROR: Invalid input parameters for API call /api/v2/customers
[2025-06-24 09:16:02] DEBUG: Parameters received: {id: null, region: "northeast"}
[2025-06-24 09:20:33] INFO: Email notification sent to 25 recipients
[2025-06-24 09:25:17] WARNING: Storage space below 15% on drive D:
Check out Concatenate String in Write-Host In PowerShell
Example 2: Search Multiple Files with Wildcards
When I need to search across multiple files, wildcards become invaluable. Here is another example to search in multiple files with wildcards using the Select-String PowerShell cmdlet.
Select-String -Pattern "Exception" -Path "C:\Logs\*.log"
This searches all .log files in the Logs directory for the term “Exception.” I’ve used this approach extensively when investigating system crashes across our server farm, enabling me to identify which component was throwing exceptions quickly.
Example 3: Case-Sensitive Searches
By default, PowerShell Select-String is case-insensitive, but sometimes you need exact matching.
Select-String -Pattern "WARNING" -Path "C:\Logs\System.log" -CaseSensitive
This example will only match “WARNING” in all capital letters. This is particularly useful when working with case-sensitive systems like our Linux integration logs, where “warning” and “WARNING” might indicate different severity levels.
Read PowerShell Substring From End
Example 4: Using Regular Expressions for Advanced Pattern Matching
The true power of Select-String lies in its support for regular expressions. Here is an example.
Select-String -Pattern "\b\d{3}-\d{2}-\d{4}\b" -Path "C:\HR\EmployeeRecords.txt"
This searches for Social Security Number patterns (like 123-45-6789) in the EmployeeRecords.txt file. I’ve implemented this in our compliance scanning tools to ensure no sensitive information is stored in plaintext, helping our office maintain HIPAA compliance.
Example 5: Display Context Around Matches
Sometimes, seeing the text surrounding a match provides crucial context.
Select-String -Pattern "Critical Failure" -Path "C:\Logs\AppLogs.txt" -Context 2,2
This returns each match along with 2 lines before and 2 lines after. When troubleshooting our payment processing system, this context often reveals the sequence of events leading to failures.
Check out String Starts With in PowerShell
Example 6: Search for Multiple Patterns
I often need to search for multiple patterns simultaneously in our monitoring systems. You can easily do this using the PowerShell Select-String cmdlet with the -Pattern parameter.
Select-String -Pattern "error", "warning", "critical" -Path "C:\Logs\ServerStatus.log"
This example searches for multiple patterns – “error”, “warning”, and “critical” – within a single command.
Example 7: Exclude Specific Patterns
Sometimes, it’s more efficient to exclude certain patterns from your search results.
Get-Content "C:\Logs\verbose.log" | Select-String -Pattern "Debug" -NotMatch
This example returns all lines that do NOT contain the word “Debug”. You can use this method to exclude specific patterns when you want to filter out noise from verbose logs.
Example 8: Find Exact Matches
For precise searching, you may want exact matches rather than partial matches. Here is how to find exact matches using the PowerShell Select-String cmdlet.
Select-String -Pattern "\bERROR\b" -Path "C:\Logs\AppLog.txt"
The word boundaries (\b) ensure that only the standalone word “ERROR” is matched, not words like “ERRORLESS”. PowerShell Select-String exact matching is essential when working with highly specific terms.
Check out How to Check if a PowerShell String Contains Special Characters
Example 9: Search Through Command Output
Select-String isn’t limited to files – you can pipe any command output to it. Here is an example.
Get-Service | Out-String -Stream | Select-String "Running"
This example filters the list of services to show only those that are running. I use this daily to check the status of critical infrastructure services quickly.
Example 10: Chain Select-String Commands for Refined Searches
One of my favorite advanced techniques is to chain multiple Select-String commands.
Select-String -Pattern "Exception" -Path "C:\Logs\*.log" | Select-String -Pattern "Database"
This first finds all lines containing “Exception” across all log files, then filters those results to only show lines that also contain “Database”. This technique allows you to store the results of one search and then perform additional quick searches against those results, which I’ve found invaluable when diagnosing complex issues.
Conclusion
These ten examples represent the techniques I use daily in enterprise environments, from basic searches to complex pattern matching and performance optimizations. They’ve saved countless hours and helped resolve critical issues faster than any GUI-based approach could.
Remember that the real power of Select-String comes from combining it with other PowerShell commands in a pipeline.
In this tutorial, I have shown 10 real examples of the PowerShell Select-String cmdlet. I encourage you to experiment with these examples in your own environment.
You may also like the following tutorials:
- How to Convert Date to String in PowerShell
- PowerShell Array of Strings
- Replace Carriage Returns in Strings Using PowerShell

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.