PowerShell Logo Small

Add-Content



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

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

SYNTAX


Add-Content [-Path] <String[]> [-Value] <Object[]> [-Credential [<PSCredential>]] [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 |
Ascii | Default | Oem | BigEndianUTF32}] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-PassThru] [-Stream [<System.String>]] [-Confirm] [-WhatIf] [-UseTransaction
[<SwitchParameter>]] [<CommonParameters>]
Add-Content [-Value] <Object[]> [-Credential [<PSCredential>]] [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii | Default | Oem
| BigEndianUTF32}] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore |
Suspend}] [-InformationVariable [<System.String>]] [-PassThru] [-Stream [<System.String>]] -LiteralPath <String[]> [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]]
[<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.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=289796
Clear-Content
Get-Content
Get-Item
Set-Content
about_Providers

REMARKS

<

Examples


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

PS C:\>add-content -path *.txt -exclude help* -value "END"



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










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

PS C:\>add-content -Path file1.log, file2.log -Value (get-date) -passthru



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 passes an object representing 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 --------------------------

PS C:\>add-content -path monthly.txt -value (get-content c:\rec1\weekly.txt)



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 --------------------------

PS C:\>add-content -value (get-content test.log) -path C:\tests\test134\logs\test134.log



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.