PowerShell: tail -f equivalent with Get-Content
Follow and filter a log file with Get-Content -Tail -Wait and Select-String.
Get-Content (alias gc) provides the equivalent of Linux tail -f through its -Tail and -Wait parameters.
Follow a file and filter
Shows the last 10 lines, then new lines as they are appended, keeping only those that contain a pattern:
Get-Content \\fileserver\logs\dns.log -Tail 10 -Wait | Where-Object { $_ -match "app-dev" }
Filter the whole file
Without following: read the entire file and keep only the matching lines:
Get-Content \\fileserver\logs\dns.log | Out-String -Stream | Select-String "app-dev"
Notes
-Waitkeeps the command running; stop it withCtrl+C.- The
-matchpattern is a regular expression.