PowerShell Logo Small

Add-Content



This is the built-in help made by Microsoft for the command 'Add-Content', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 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

Appends content, such as words or data, to a file.

SYNTAX


Add-Content [-Path] <String[]> [-Value] <Object[]> [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include
<String[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Add-Content [-Value] <Object[]> [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include <String[]>]
[-PassThru] -LiteralPath <String[]> [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Add-Content [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii | Default | Oem}] [-Force] [-Stream
<string>] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Add-Content cmdlet appends content to a specified item or file. You can specify the content by typing the content in the command or by
specifying an object that contains the content.

In file system drives, the Add-Content cmdlet appends the content you specify to the end of a file. This cmdlet is not valid on folders.

Note: This custom cmdlet help file explains how the Add-Content cmdlet works in a file system drive. For information about the Add-Content
cmdlet in all drives, type "Get-Help Add-Content -Path $null" or see Add-Content at http://go.microsoft.com/fwlink/?LinkID=113278.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkId=204573
Add-Content
(generic): http://go.microsoft.com/fwlink/?LinkID=113278
FileSystem Provider
Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-Path

REMARKS

<

Examples


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

C:\PS>Add-Content -Path *.txt -Exclude help* -Value "END"



Description

-----------

This command adds "END" to all text files in the current directory, except for those with file names that begin with "help."








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

C:\PS>Add-Content -Path file1.log, file2.log -Value (get-date) -PassThru



Description

-----------

This command adds the date to the end of the File1.log and File2.log files and then displays the date at the command line.

The command uses the Get-Date cmdlet to get the date, and it uses the Value parameter to pass the date to Add-Content. The PassThru parameter
sends the added content through the pipeline. Because there is no other cmdlet to receive the passed content, it is displayed at the command
line.








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

C:\PS>Add-Content -Path monthly.txt -Value (Get-Content c:\rec1\weekly.txt)



Description

-----------

This command adds the contents of the Weekly.txt file to the end of the Monthly.txt file. It uses the Get-Content cmdlet to get the contents
of the Weekly.txt file, and it uses the Value parameter to pass the content of weekly.txt to Add-Content. The parentheses ensure that the
Get-Content command is complete before the Add-Content command begins.

You can also copy the content of Weekly.txt to a variable, such as $w, and then use the Value parameter to pass the variable to Add-Content.
In that case, the command would be "add-content -path monthly.txt -value $w".








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

C:\PS>Add-Content -Value (Get-Content test.log) -Path C:\tests\test134\logs\test134.log



Description

-----------

This command creates a new directory and file and copies the content of an existing file to the newly created file.

This command uses the Add-Content cmdlet to add the content. The value of the Value parameter is a Get-Content command that gets content from
an existing file, Test.log.

The value of the path parameter is a path that does not exist when the command runs. In this example, only the C:\Tests directories exist. The
command creates the remaining directories and the Test134.log file.

The Force parameter is not required for this command. Add-Content creates directories to complete a path even without the Force parameter.








-------------------------- EXAMPLE 5 --------------------------

C:\PS>Get-Content test.xml | Add-Content final.xml -Force -Encoding UTF8



Description

-----------

This command appends the contents of the final.xml file to the contents of the test.xml file.

The command uses the Force parameter so that the command is successful even if the Final.xml file is read-only. It uses the Encoding parameter
to specify an encoding of UTF-8.