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 ...

Get Pro Windows PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.