Get-Content - PowerShell command help and examples

Gets the content of the item at the specified location. (Get-Content)


NAME
Get-Content
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[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>] Get-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]
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 an object for each line.
PARAMETERS
-Credential <PSCredential> Specifies a user account that has permission to perform this action. The default is the current user. Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter is not supported by any providers that are installed with Windows PowerShell. Required? false Position? named Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -Exclude <string[]> Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Filter <string> Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Force [<SwitchParameter>] Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Include <string[]> Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -LiteralPath <string[]> Specifies the path to an item. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences. Required? true Position? 1 Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -Path <string[]> Specifies the path to an item. Get-Content retrieves the content of the item. Wildcards are permitted. The parameter name ("Path" or "FilePath") is optional. Required? true Position? 1 Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -ReadCount <Int64> Specifies how many lines of content are sent through the pipeline at a time. The default value is 1. A value of 0 (zero) sends all of the content at one time. This parameter does not change the content displayed, but it does affect the time it takes to display the content. As the value of ReadCount increases, the time it takes to return the first line increases, but the total time for the operation decreases. This can make a perceptible difference in very large items. Required? false Position? named Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -TotalCount <Int64> Specifies how many lines of content are retrieved. The default is -1 (all lines). Required? false Position? named Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -UseTransaction [<SwitchParameter>] Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false <CommonParameters> This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, type, "get-help about_commonparameters".
INPUTS
None You cannot pipe input to Get-Content.
OUTPUTS
Object Get-Content returns objects that represent the content that it gets. The object type depends on the content type.
NOTES
You can also refer to Get-Content by its built-in aliases, "cat", "type" and "gc". For more information, see about_Aliases. The Get-Content cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type "Get-PsProvider". For more information, see about_Providers.

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-Content 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 first 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 notation to get the last line (indicated by "-1") of the resulting set. RELATED LINKS Online version: http://go.microsoft.com/fwlink/?LinkID=113310 about_Providers Add-Content Set-Content Clear-Content C:\Windows>powershell get-help Get-ItemProperty -full

Microsoft Windows [Version 10.0.19045.3693]
Copyright (c) 2023 Microsoft Corporation.

ColorConsole [Version 3.7.1000] PowerShell 2.0-Export

Windows 11, 10, 8.1, 8, 7 / Server 2022, 2019, 2016











Windows-10


... Windows 10 FAQ
... Windows 10 How To


Windows 10 How To


... Windows 11 How To
... Windows 10 FAQ



PowerShell: Gets the content of the item at the specified location.

HTTP: ... PS_Windows/en/Get-Content.htm
0.077
14121
What is USB (interface)?
WINDOWS SETTING MS SETTINGS PEN
WINDOWS SETTING MS SETTINGS SIGNINOPTIONS LAUNCHFINGERPRINTENROLLMENT
WINDOWS SETTING MS SETTINGS PRIVACY VIDEOS
Was sind proprietäre Dateiformate?
Wo ist der Unterschied zwischen Windows-7 Home, Professional und Ultimate?
Was ist Zeitlosigkeit?
What is the difference between Windows 7 Ultimate x64 to x86?
What is a Rubik's Cube?
What is a histogram?



(0)