Successfully added
PowerShell Coding Samples
by Patrik
Get First Line of File in PowerShell
If we want to only get the first line of a file we can use the Get-Content cmdlet and pipe this to the Select-Object cmdlet and use the First parameter to retrieve one line.
Get-Content -Path "C:\file.txt" | Select-Object -First 1
Alternatively, this could also be done on an object
$content = Get-Content -Path "C:\file.txt" ... $firstLine = Get-Content $content | Select-Object -First 1
Referenced in:
Comments