You are currently viewing PowerShell Get-Content Cmdlet

PowerShell Get-Content Cmdlet

PowerShell Get-Content Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Add-Content cmdlet in PowerShell.

https://cloudaffaire.com/powershell-add-content-cmdlet/

In this blog post, we will discuss Get-Content cmdlet in PowerShell. You can use Get-Content cmdlet to read from a file in PowerShell. The Get-Content cmdlet gets the content of the file specified by the path parameter. You can get content of multiple files at the same time using Get-Content cmdlet.

Get-Content Cmdlet Syntax:

Get-Content Cmdlet Argument List:

  • Credential: Credentials to impersonate another user, or elevate your credentials when running this cmdlet.
  • Delimiter: Specifies the delimiter that Get-Content uses to divide the file into objects while it reads. The default is \n, the end-of-line character.
  • Encoding: Specifies the type of encoding for the target file. The default value is Default.
  • Exclude: Specifies, as a string array, an item or items that this cmdlet excludes in the operation. The value of this parameter qualifies the Path parameter.
  • Filter: Specifies a filter to qualify the Path parameter. The FileSystem provider is the only installed PowerShell provider that supports the use of filters.
  • Force: Force will override a read-only attribute or create directories to complete a file path. The Force parameter does not attempt to change file permissions or override security restrictions.
  • Include: Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value of this parameter qualifies the Path parameter.
  • LiteralPath: Specifies a path to one or more locations. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards.
  • Path: Specifies the path to an item where Get-Content gets the content. Wildcard characters are permitted.
  • Raw: Ignores newline characters and returns the entire contents of a file in one string with the newlines preserved.
  • ReadCount: 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.
  • Stream: Gets the contents of the specified alternate NTFS file stream from the file. Enter the stream name. Wildcards are not supported.
  • Tail: Specifies the number of lines from the end of a file or other item. You can use the Tail parameter name or its alias, Last.
  • TotalCount: Specifies the number of lines from the beginning of a file or other item. The default is -1 (all lines).
  • UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
  • Wait: Keeps the file open after all existing lines have been output. While waiting, Get-Content checks the file once each second and outputs new lines if present.

PowerShell Get-Content Cmdlet:

Get Content Of A File In PowerShell:

Get Contents Of Multiple Files In PowerShell:

Get Contents Of Multiple Files Excluding Some Files In PowerShell:

Get Contents Of Multiple Files Along With File Names In PowerShell:

Get Specific Number Of Lines From A File In PowerShell:

Change The Delimiter From Default New Line To Some Other In PowerShell:

Get A Line Containing Specific Pattern From A File In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss Set-Content cmdlet in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply