PowerShell Logo Small


This is the built-in help made by Microsoft for the command 'Clear-Content', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' 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.


Deletes the contents of an item, but does not delete the item.


Clear-Content [-Path] <String[]> [-Credential [<PSCredential>]] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction
{SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Stream [<System.String>]] [-Confirm] [-WhatIf] [-UseTransaction
[<SwitchParameter>]] [<CommonParameters>]
Clear-Content [-Credential [<PSCredential>]] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Stream [<System.String>]] -LiteralPath <String[]> [-Confirm] [-WhatIf] [-UseTransaction
[<SwitchParameter>]] [<CommonParameters>]

Search powershellhelp.space


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. Clear-Content is similar to Clear-Item, but it works on items with contents, instead of items with values.



Online Version: http://go.microsoft.com/fwlink/p/?linkid=289798




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

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

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 --------------------------

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

This command deletes the contents of all files in the current directory with the ".log" file name extension, including files with the read-only attribute. The asterisk (*)
in the path represents all items in the current directory. The Force parameter makes the command effective on read-only 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 --------------------------

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

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