Add-Content
Use Add-Content to append a value to the end of a file, leaving existing content in place.
Documentation: Microsoft Learn — Add-Content
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Add-Content [-Path] <String[]> [-Value] <Object[]> [-Encoding <Encoding>] [-Force] [-NoNewline] [-WhatIf] [<CommonParameters>]- Stage 1Add-Content
-Path -Value -Encoding -Force -NoNewline -WhatIf
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Add-Content -Path 'C:\Temp\run.log'
Show reference output
Sample output · fictional data, shaped like the real thing
2026-10-09 14:31:02 INFO Backup started 2026-10-09 14:31:07 INFO 42 files copied step 1 complete
Add-Content -Path 'C:\Temp\run.log' (2)
Show reference output
Sample output · fictional data, shaped like the real thing
2026-10-09 14:31:02 INFO Backup started 2026-10-09 14:31:07 INFO 42 files copied step 1 complete 14:32:10 started
Add-Content -Value $lines;
Show reference output
Sample output · fictional data, shaped like the real thing
2026-09-10 23:41:02 INFO Backup started 2026-09-10 23:41:07 INFO 42 files copied 2026-09-10 23:41:08 INFO Backup completed
Parameters
Parameter definitions:
-Path-Value-Encoding-Force-NoNewline-WhatIf
Practical use and troubleshooting
Practical scenario: Use Add-Content when you need to append a value to the end of a file, leaving existing content in place. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: Access denied when appending usually points to file permissions or a file held open by another process. Check the target ACL and the owning application before retrying. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Set-Content. Add-Content appends to existing content; Set-Content replaces it. Choose deliberately when maintaining a log rather than creating a fresh report. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Add-Content Use Add-Content to append a value to the end of a file, leaving existing content in place.
Next: Clear-Content