You are here:

WindowsManagement.com > PowerShell > PowerShell 1.0 > Add-Content
ActiveXperts Network Monitor 2019 proactively manages network servers, devices, databases and more.

Add-Content - PowerShell 1.0

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.

Add-Content


Description
Back up your Hyper-V VMs Easy & Fast. 100% built for Hyper-V. Free for 2 VMs, forever.

Usage


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

   -passThru
       Pass the object created by this cmdlet through the pipeline.

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

   -whatIf
       Describe the command without actually executing it.

   -confirm
       Prompt for confirmation before executing the command.

   CommonParameters
       Supports: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable
       For more info, type, "get-help about_commonparameters".

Example(s)
1) 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"

2) 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.)

3) 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.