As a sysadmin, I often find myself digging through logs, config files, and scripts to troubleshoot issues or verify configurations. One of the most useful PowerShell one-liners in my daily toolkit is this:
Get-ChildItem -Path "C:\Your\Directory" -Recurse -File | Select-String -Pattern "YourSearchText"
This command recursively scans all files in the specified directory and searches for the string "YourSearchText"
. It’s incredibly handy when you’re hunting down error messages, checking for legacy code, or verifying that certain settings are applied across multiple files.
A few real-world uses:
- Searching logs for specific errors
- Auditing scripts for hardcoded credentials or IPs
- Verifying config files for deprecated settings
Quick, powerful, and easy to drop into any routine check or investigation.
Try it with different patterns or add -List
to Select-String
to return only the first match per file — super useful when you’re only interested in whether something exists at all.