Using the Clear-Content Cmdlet

Erasing the Contents of a File

The Clear-Content cmdlet enables you to erase the contents of a file without deleting the file itself. For example, suppose you run this command:

Clear-Content c:\scripts\test.txt

When you execute that command the file Test.txt will still be in the folder C:\Scripts; there just won’t be any data of any kind in the file:

Did we hear someone ask if wildcard characters can be used with Clear-Content? You bet; this command erases the contents of any file in C:\Scripts whose file name starts with the letter E:

Clear-Content c:\scripts\e*

And, no, you are not limited to erasing only text files. Want to delete all the data in an Excel spreadsheet? Hey, why not:

Clear-Content c:\scripts\test.xls

And this command erases contents of the Word document C:\Scripts\Test.doc:

Clear-Content c:\scripts\test.doc
Clear-Content Aliases
  • clc