PowerTip: Read First Line of File with PowerShell


Summary: Learn how to read only the first line of a file by using Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to read only the first line of a file?

Hey, Scripting Guy! Answer Introduced in Windows PowerShell 3.0, you can use the -First parameter, for example:

Get-Content C:\fso\batteryReport.txt -First 1

Comments (1)

  1. Simple but cool. I have used get-content in most of my codes

Skip to main content