PowerShell Daily Dose: Get-Content

Get-Content gets the contents of the specified file. A simple usage example:

PS C:\test> Get-Content ps.txt
some random
text for
testing powershell
get-content cmdlet...

Note that you don’t have to type the whole cmdlet; you can use one of the aliases of this cmdlet: cat, gc or type.

This command returns a collection of objects. Each object represents a line of content in the file. You will start realizing the potential of this command as you learn more commands. For example, you can pipe the output of this command to a looping command like ForEach-Object.

There are several different options that you can pass on to the command. For example you can specify the number of lines to read, pass credentials to use, filter strings, include and exclude strings and many more. For more detailed info please check the get-content help page.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s