PowerShell Logo Small

Get-Content



This is the built-in help made by Microsoft for the command 'Get-Content', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Gets the content of the item at the specified location.

SYNTAX


Get-Content [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Read
Count <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]
Get-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-ReadCount <
Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file. It reads the content one l
ine at a time and returns an object for each line.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113310
about_Providers
Add-Content
Set-Content
Clear-Content

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-content -Path C:\Chapters\chapter1.txt



Description
-----------
This command displays the content of the Chapter1.txt file on the console. It uses the Path parameter to specify the name of the item. Get-Conten
t actually passes the content down the pipeline, but because there are no other pipeline elements, the content is formatted and displayed on the
console.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-content c:\Logs\Log060912.txt -totalcount 50 | set-content sample.txt



Description
-----------
This command gets the first 50 lines of the Log060912.txt file and stores them in the sample.txt file. The command uses the Get-Content cmdlet to
get the text in the file. (The name of Path parameter, which is optional, is omitted.) The TotalCount parameter limits the retrieval to the firs
t 50 lines. The pipeline operator (|) sends the result to Set-Content, which places it in the sample.txt file.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>(get-content cmdlets.txt -totalcount 5)[-1]



Description
-----------
This command gets the fifth line of the Cmdlets.txt text file. It uses the TotalCount parameter to get the first five lines and then uses array n
otation to get the last line (indicated by "-1") of the resulting set.