Skip to content
mnaoumov.dev
Go back

PowerShell Get-Content vs _System.IO.File___ReadAllText

The difference between

Get-Content "FileName.txt"

and

[System.IO.File]::ReadAllText("FileName.txt")

That first one returns array of lines in the file and second returns one string for whole file.

There are couple of other ways to achieve second behavior with Get-Content as well

According to this in PowerShell 3 you can do that using new parameter Raw

Get-Content "FileName.txt" -Raw

The solution that works in PowerShell 2:

Get-Content "FileName.txt" | Out-String

Share this post on:

Previous Post
PowerShell + XAML => GUI
Next Post
WTF Exception.ToString() and FaultException