This article describes how to remove or empty the contents of a file in PowerShell, use VBScript to create the FSO first, then open the file, and then modify the file; PowerShell empty the file as long as a clear-content.
The so-called empty file, that is, a text file inside the contents of all deleted, using Notepad and other tools to open, see the content is empty, the size of the file is also 0KB. Let's take a look at how the PowerShell is done in the empty file.
First, introduce a cmdlet, that is clear-content. First look at its basic introduction:
Copy Code code as follows:
Name
Clear-content
Summary
Deletes the contents of an item, such as deleting text from a file, but does not delete the item. (small part of a sentence: that is, only delete the file empty, do not delete the file itself.) )
Grammar
clear-content [-literalpath] [-credential] [-excl
Ude] [-filter] [-force] [-include] [-confirm
] [-whatif] [-usetransaction] []
clear-content [-path] [-credential] [-exclude ring[]>] [-filter] [-force] [-include] [-confirm] [-Wha
TIF] [-usetransaction] []
Small series: This syntax looks very complex, in fact, the simplest use is: clear-content < file path, other parameters are some control authority, some give an unprecedented hint, and some are completed bulk operation. These parameters can be understood when there is an in-depth requirement. Let's take a look at a simple use case:
Copy Code code as follows:
PS c:\users\splaybow> Echo hello,world! >d:\1.txt
PS c:\users\splaybow> Type D:\1.txt
Hello
world!
PS c:\users\splaybow> clear-content D:\1.txt
PS c:\users\splaybow> Type D:\1.txt
PS c:\users\splaybow>
Explain the meaning of this code, using echo to "hello,world!" Output to a new file "D:\1.txt" and then use Clear-content to empty the contents of the file. and the contents of the file are displayed when the Qing is unprecedented and empty.
About PowerShell use Clear-content to remove empty file content, this article on the introduction so much, I hope to help you, thank you!