Friday, October 26, 2018

How do you use cmdlet Add-Content in Windows PowerShell?

You can do a lot of  things with Add-Content.

These are all the parameters you can use with Add-Content.

Add-Content
   [-Value]
   [-PassThru]
   [-Path]
   [-Filter ]
   [-Include ]
   [-Exclude ]
   [-Force]
   [-Credential ]
   [-WhatIf]
   [-Confirm]
   [-UseTransaction]
   [-NoNewline]
   [-Encoding ]
   [-Stream ]
   []


The following example demonstrates on of them using the -Path parameter.

Now create two (or more) empty files in an allowed folder:
I created two text files (empty) and saved them to a folder:

C:\Users\Jayaram\Documents\Jay_1.txt
C:\Users\Jayaram\Documents\Jay_2.txt


Now using Add-Content, I will add current date to the end of these files. These being empty, the dates will added to the top of the files.

Now launch the Windows PowerShell ISE and run this code:


Now go check the files and you should see the dates added.




No comments: