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

      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[]] -LiteralPath string[]
               [-NoNewline] [-PassThru] [-Stream string] [-UseTransaction]
                  [-Confirm] [-WhatIf] [CommonParameters]

      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[]]
               [-NoNewline] [-PassThru] [-Stream string] [-UseTransaction]
                  [-Confirm] [-WhatIf] [CommonParameters]

      Add-Content [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii | Default | Oem}]
         [-Force] [-Stream string]
            [-Confirm] [-WhatIf] [-UseTransaction] [CommonParameters]

   -Path path
       The path to the item {may be piped} Wildcards are permitted.
       If you specify multiple paths, use commas to separate the paths.

   -LiteralPath string[]
       Path to the items. No wildcards.
       The value is used exactly as typed. 
       If the path includes escape characters, enclose it in single quotation marks.

   -Include string[]
       Qualify the Path parameter. Enter a path or wildcard pattern: "*.txt"

   -Exclude string[]
       Omit the specified items. Enter a path or wildcard pattern: "*.txt" 

   -Filter string[]
       A filter in the provider's format or language.
       The exact syntax of the filter (wildcard support etc) depends on the provider.
       Filters are more efficient than -include/-exclude, because the provider
       applies the filter when retrieving the objects, rather than having 
       PowerShell filter the objects after they are retrieved.     
  -Value Object[]
       The content to be added. Type a quoted string, such as "Sample text"
       or specify an object that contains content, such as the DateTime object
       that Get-Date generates. 
       You cannot specify the contents of a file by typing its path, because 
       the path is just a string, but you can use a Get-Content command to get 
       the content and pass it to the Value parameter.

       Pass the object created by this cmdlet through the pipeline.

       Override restrictions that prevent the command from succeeding, just
       so the changes do not compromise security. For example, Force will
       override the read-only attribute or create directories to complete a
       file path, but it will not attempt to change file permissions.

   -Credential PSCredential
       Present a user/password credential to validate access to the file.
       This is not yet supported in any Windows PowerShell core commands.

       Prompt for confirmation before executing the command.

       Describe what would happen if you executed the command without actually executing it.

       Include the command in the active transaction.

   -Encoding CharSet[Dynamic Parameter (FileSystem Only)]
       Encode in a specific character set:
           Unknown           Unknown or invalid. The data can be treated as binary.
           String            Use the encoding type for a string.                
           Unicode           UTF-16 format little-endian byte order.
           Byte              Encode characters as a sequence of bytes.
           BigEndianUnicode  UTF-16 format big-endian byte order.
           BigEndianUTF32    UTF-32 format big-endian byte order.
           UTF8              UTF-8 format.
           UTF7              UTF-7 format.
           ASCII             ASCII (7-bit) character set.

   -Stream string
        Add the content to the specified alternate data stream.
        If the stream does not yet, exist, Add-Content creates it.
        Enter the stream name. Wildcards are not supported.
        Stream is a dynamic FileSystem parameter (PowerShell 3.0+)

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Standard Aliases for Add-Content: ac


Add a text string to the end of every .TXT file in the current directory:

C:\PS> add-content -path *.txt -value "This is the end"

Add the content of the file Cats.txt to the end of the file Pets.txt:

C:\PS> add-content -path pets.txt -value (get-content c:\docs\cats.txt)

The parentheses above insure Get-Content can complete before the Add-Content starts.
We specify -value to pass the contents of the file (rather than an object.)

Add the current date to a logfile:

C:\PS> add-content -Path MyLogfile.txt -Value (get-date) -passthru

The -passthru option will display the content as it is added, it actually passes an object through the pipeline, which by default is passed back to the command line.

“Content is king” - Webmonkey circa 1996


Get-Content - Get content from item (specific location)
- Set content in the item (specific location)
- Remove content from a file/item
Escape characters, Delimiters and Quotes - Add special characters (newlines, tabs etc)
Get-Item - Get a file object or get a registry (or other namespace) object
get-help - about_namespace

Copyright © 1999-2017
Some rights reserved