PowerShell: Read File
Get-Content
has alias of gc
Get-Content filePath
- return the file content as a array of strings. Each element is a line.
Get-Content filePath -TotalCount n
- return first n lines as a array of strings.
Get-Content filePath -tail n
- return last n lines as a array of strings.
Get-Content filePath -raw
- return whole file as one string.
Get-Content filePath -Encoding utf8
- Use utf8 encoding.
Here's a alternative, using .NET method:
[IO.File]::ReadAllText(file_path)
- return the content of the file, as a string.