concept get - Content in category powershell

appears as: Get-Content, Get-Content, Get-Content
Windows PowerShell in Action, Third Edition

This is an excerpt from Manning's book Windows PowerShell in Action, Third Edition.

Next, instead of displaying the directory listing, you’ll save it into a file using output redirection as in other shell environments. In the following example, you’ll get information about a file named somefile.txt in the root of the C: drive. Using redirection, you direct the output into a new file, c:\foo.txt, and then use the Get-Content (you can use the alias of cat or type if you prefer) command to display what was saved. Here’s what this looks like:

Now it’s possible to do the same thing by using Get-Content or even the file system name trick you learned in chapter 4:

Where-Object and Get-Content’s -ReadCount parameter

On occasion, a question comes up about the Get-Content (alias gc) cmdlet and how its -ReadCount parameter works. This can be an issue particularly when using this cmdlet and parameter with Where-Object to filter the output of Get-Content. The issue comes up when the read count is greater than 1. This causes PowerShell to act as if some of the objects returned from Get-Content are being skipped and affects both ForEach-Object and Where-Object. After all, these cmdlets are supposed to process or filter the input one object at a time, and this isn’t what appears to be happening.

Listing 16.1. Get-HexDump
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest