PowerShell Logo Small

Clear-Content



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

SYNOPSIS

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

SYNTAX


Clear-Content [-Path] <String[]> [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include <String[]>]
[-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Clear-Content [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include <String[]>] -LiteralPath <String[]>
[-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Clear-Content [-Stream <string>] [<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,
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.

In the file system, Clear-Content clears the content in a file, but does not delete the file. It has no effect on folders.

Note: This custom cmdlet help file explains how the Clear-Content cmdlet works in a file system drive. For information about the Clear-Content
cmdlet in all drives, type "Get-Help Clear-Content -Path $null" or see Clear-Content at http://go.microsoft.com/fwlink/?LinkID=113282.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkId=204573
Add-Content
(all providers); http://go.microsoft.com/fwlink/?LinkID=113278
FileSystem Provider
Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-Path

REMARKS

<

Examples


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

C:\PS>Get-Content C:\Test\Copy-Script.ps1 -Stream Zone.Identifier

[ZoneTransfer]
ZoneId=3

C:\PS>Clear-Content C:\Test\Copy-Script.ps1 -Stream Zone.Identifier

C:\PS>Get-Content C:\Test\Copy-Script.ps1 -Stream Zone.Identifier
C:\PS>



Description

-----------

This example shows how the Clear-Content cmdlet clears the content from an alternate data stream while leaving the stream intact.

The first command uses the Get-Content cmdlet to get the content of the Zone.Identifier stream in the Copy-Script.ps1 file, which was
downloaded from the Internet.

The second command uses the Clear-Content cmdlet to clear the content.

The third command repeats the first command. It verifies that the content is cleared, but the stream remains. If the stream were deleted, the
command would generate an error.

You can use a method like this one to clear the content of an alternate data stream. However, it is not the recommended way to eliminate
security checks that block files that are downloaded from the Internet. If you verify that a downloaded file is safe, use the Unblock-File
cmdlet.








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

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

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

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