Home > Software engineering >  Powershell how to search the file and then open then tail the file based on the first search
Powershell how to search the file and then open then tail the file based on the first search

Time:01-20

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

CodePudding user response:

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
  •  Tags:  
  • Related