O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

15.1. Reading Content

Everything about a file's content in PowerShell revolves around the two cmdlets Get-Content and Set-Content. While they can get and set raw binary data, by default, they are oriented toward working with text. For example, here is how we can use Get-Content to retrieve the text stored in a sample file called test_people.txt:

PS> Get-Content .\test_people.txt
Michael Johnson
John Smith

Jane Doe

Users with a background in a different programming language may expect that Get-Content will return a string with the file contents. Not quite—the cmdlet is line oriented and returns an array of strings, each representing a line from the original text. Here is how to verify that; the result returned from Get-Content and our file is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required