PowerShell Logo Small

Clear-Content



This is the built-in help made by Microsoft for the command 'Clear-Content', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Deletes the contents of an item, such as deleting the text from a file, but does not delete the item.

SYNTAX


Clear-Content [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Co
nfirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]
Clear-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Confirm]
[-WhatIf] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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, th
e item exists, but it is empty. Clear-Content is similar to Clear-Item, but it works on files instead of on aliases and variables.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113282
about_Providers
Get-Content
Set-Content
Add-Content
Get-Item

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>clear-content ..\SmpUsers\*\init.txt



Description
-----------
This command deletes all of the content from the "init.txt" files in all subdirectories of the SmpUsers directory. The files are not deleted, but
they are empty.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>clear-content -path * -filter *.log -force



Description
-----------
This command deletes the contents of all files in the current directory with the ".log" file name extension, including files with the read-only a
ttribute. The asterisk (*) in the path represents all items in the current directory. The Force parameter makes the command effective on read-onl
y files. Using a filter to restrict the command to files with the ".log" file name extension instead of specifying "*.log" in the path makes the
operation faster.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>clear-content c:\Temp\* -Include Smp* -Exclude *2* -whatif



Description
-----------
This command requests a prediction of what would happen if you submitted the command: "clear-content c:\temp\* -include smp* -exclude *2*". The r
esult lists the files that would be cleared; in this case, files in the Temp directory whose names begin with "Smp", unless the file names includ
e a "2". To execute the command, run it again without the Whatif parameter.