Erasing the Contents of a File from PowerShell
The Clear-Content cmdlet deletes the contents of an item, such as deleting the text from a file, but it does not delete the item. As a result, the item exists, but it is empty. For example, suppose you run following command:


Code:

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.

Wildcards are permitted with Clear-Content. Following command erases the contents of any file in C:\Scripts whose file name starts with the letter E:


Code:

Clear-Content c:\scripts\e*



You are not limited to erasing only text files. Want to delete all the data in an Excel spreadsheet:


Code:

Clear-Content c:\scripts\test.xls



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


Code:

Clear-Content c:\scripts\test.doc



Clear-Content Aliases:

clc




............................................................................................

FreeBooter
Erasing the Contents of a File from PowerShell 1363

Co-Administrator