PowerShell Logo Small

Add-Content



This is the built-in help made by Microsoft for the command 'Add-Content', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' 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

Adds content to the specified items, such as adding words to a file.

SYNTAX


Add-Content [-LiteralPath] <string[]> [-Value] <Object[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Includ
e <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]
Add-Content [-Path] <string[]> [-Value] <Object[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <stri
ng[]>] [-PassThru] [-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 specif
ying an object that contains the content.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113278
about_Providers
Get-Content
Set-Content
Clear-Content
Get-Item

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 G
et-Date cmdlet to get the date, and it uses the Value parameter to pass the date to Add-Content. The PassThru parameter passes an object represen
ting the added content through the pipeline. Because there is no other cmdlet to receive the passed object, 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 t
he 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 t
hat 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 co
mmand 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.