PowerShell is great tool for analysing log files. Using few PowerShell cmdlets pipelined together we can find errors:
Get-Content *.log | Select-String error | Sort-Object | Get-Unique | Out-File error.log -Width 1000 -Encoding UTF8
- Get-Content – gets the content of log files
- Select-String – finds text in content
- Sort-Object – sorts objects
- Get-Unique – returns unique errors from a sorted list
- Out-File – sends output to file using specified encoding and line width
This simple, but powerfull one line code snippet can help find specific items in log files fast and effectively.
If you are interested in PowerShell automation, take my Udemy course Improve your productivity with PowerShell.