You are currently viewing PowerShell Add-Content Cmdlet

PowerShell Add-Content Cmdlet

PowerShell Add-Content Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Compare-Object cmdlet in PowerShell.

https://cloudaffaire.com/powershell-compare-object-cmdlet/

In this blog post, we will discuss Add-Content cmdlet in PowerShell. You can use Add-Content cmdlet to append data to an existing file in PowerShell. You need to provide the file name using ‘path’ parameter and the content to write using ‘value’ parameter. You can also write to multiple files at once using Add-Content cmdlet.

Add-Content Cmdlet Syntax:

Add-Content Cmdlet Argument List:

  • Confirm: Prompts you for confirmation before running the cmdlet.
  • Credential: Specifies a user account that has permission to perform this action. The default is the current user.
  • Encoding: Specifies the type of encoding for the target file. The default value is Default.
  • Exclude: 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.
  • Filter: Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter.
  • Force: Overrides the read-only attribute, allowing you to add content to a read-only file.
  • Include: Adds only the specified items. The value of this parameter qualifies the Path parameter.
  • LiteralPath: Specifies the path to the items that receive the additional content. Unlike Path, the value of LiteralPath is used exactly as it is typed.
  • NoNewline: Indicates that this cmdlet does not add a new line or carriage return to the content.
  • PassThru: Returns an object representing the added content. By default, this cmdlet does not generate any output.
  • Path: Specifies the path to the items that receive the additional content. Wildcards are permitted. If you specify multiple paths, use commas to separate the paths.
  • Stream: Specifies an alternative data stream for content. If the stream does not exist, this cmdlet creates it. Wildcard characters are not supported.
  • UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
  • Value: Specifies the content to be added. Type a quoted string, such as This data is for internal use only, or specify an object that contains content.
  • WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.

PowerShell Add-Content Cmdlet:

Append Some Data To A File In PowerShell:

Append Some Data To Multiple Files In PowerShell:

Append Some Data To Multiple Files Excluding Some Files In PowerShell:

Write Some Data To A Read Only File In PowerShell:

Write Content Of One File To Another File In PowerShell:

Write Output Of A Cmdlet To A File In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss Get-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