PowerShell Logo Small

Get-Content



This is the built-in help made by Microsoft for the command 'Get-Content', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' 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 [-Path] <String[]> [-Credential [<PSCredential>]] [-Delimiter [<System.String>]] [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 |
UTF32 | Ascii | Default | Oem | BigEndianUTF32}] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Raw] [-ReadCount [<Int64>]] [-Stream [<System.String>]] [-Tail [<Int32>]] [-TotalCount
[<Int64>]] [-Wait] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Get-Content [-Credential [<PSCredential>]] [-Delimiter [<System.String>]] [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii |
Default | Oem | BigEndianUTF32}] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop | Continue |
Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Raw] [-ReadCount [<Int64>]] [-Stream [<System.String>]] [-Tail [<Int32>]] [-TotalCount [<Int64>]]
[-Wait] -LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] [<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 line at a time and returns a
collection of objects , each of which represents a line of content.


Beginning in Windows PowerShell 3.0, Get-Content can also get a specified number of lines from the beginning or end of an item.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=290491
Add-Content
Clear-Content
Set-Content
about_Providers

REMARKS

<

Examples


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

PS C:\>Get-Content -Path C:\Chapters\Chapter1.txt



This command gets the content of the Chapter1.txt file. It uses the Path parameter to specify the name of the item. Get-Content actually passes the content down the
pipeline, but because there are no other pipeline elements, the content is formatted by default and displayed at the command line.






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

PS C:\>Get-Content c:\Logs\Log060912.txt -TotalCount 50 | Set-Content Sample.txt



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 content retrieved to the first 50 lines. The pipeline operator (|) sends the
result to the Set-Content cmdlet, which places it in the Sample.txt file.






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

PS C:\>(Get-Content Cmdlets.txt -TotalCount 5)[-1]



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 notation to get the last line
(indicated by "-1") of the resulting set.






-------------------------- EXAMPLE 4 --------------------------

PS C:\>dir .\*.txt | ForEach {Get-Content $_ -Head 1; Get-Content $_ -Tail 1}



This command gets the first and last lines of each text file in the current directory. The command uses the Tail parameter and the Head alias of the TotalCount parameter