WeiJie
WeiJie

Reputation: 5

Powershell how to search the file and then open then tail the file based on the first search

How do open tail the first text file I search in descending order?

Get-Content -Tail
Get-ChildItem -Force -Recurse -File -Path "C:\*.txt" -ErrorAction SilentlyContinue | Where-Object { $_.CreationTime.Date -lt (Get-Date).Date } | Sort CreationTime -Descending

Upvotes: 0

Views: 123

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174515

Use Select-Object -First 1 to discard everything after the first input object:

Get-ChildItem ... |Where-Object {...} | Sort ... |Select-Object -First 1 |Get-Content -Tail

Upvotes: 2

Related Questions