TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Clear-Content

PowerShell Clear-Content with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

PowerShell Clear-Content

The Clear-Content cmdlet deletes the content of an item, but it does not delete the item, such as deleting the text from the file. As a result, an item exists, but that item is empty. This cmdlet works on an item with content, instead of items with values. The clc is the alias for this cmdlet.

Syntax

Clear-Content 
[-Path <string[]>]
[-Force]
[-Credential <pscredential>] 
[-WhatIf]
[-Filter <string>] 
[-Include <string[]>] 
[-Exclude <string[]>] 
[-Confirm] 
[-UseTransaction] 
[-Stream <string>]  
[<CommonParameters>]

Clear-Content 
[-LiteralPath <string[]>]
[-Force]
[-Credential <pscredential>] 
[-WhatIf]  
[-Filter <string>] 
[-Include <string[]>] 
[-Exclude <string[]>] 
[-Confirm] 
[-UseTransaction] 
[-Stream <string>] 
[<CommonParameters>]

Parameters

-Path

The -Path parameter is used to specify the path to that item from which content is deleted. Wildcard characters are accepted. The path must be the path to the items, not to the containers. It is required, but the name of a parameter -Path is optional.

-LiteralPath

The -LiteralPath parameter is used to specify the paths to the items from which content is deleted. Unlike the -Path parameter, the value of it used exactly as it is typed. Wildcard characters are not accepted.

If the path includes the escape characters, enclose it in single quotation marks. Single quotation mark tells the Windows PowerShell that it should not interpret any character as an escape sequence.

-Force

The -Force parameter is used to force the command to execute without asking for user confirmation.

-WhatIf

The -WhatIf parameter displays what would happen if the cmdlet runs. The cmdlet does not execute.

-Filter

The -Filter parameter is used to specify a filter in the provider's language or format. The value of it qualifies the -Path parameter. This parameter is more efficient as the provider applies the filters when the cmdlet gets the object, rather than having PowerShell filters the object after they're accessed.

-Include

The content that this cmdlet clears specified as a string array. The value of -Include parameter qualifies the -�Path parameter. Enter a pattern or a path element, such as *.txt. Wildcard characters are accepted.

-Exclude

The content that this cmdlet omits from the path is specified as a string array. The value of it qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. Wildcard characters are accepted.

-Confirm

The -Confirm parameter prompts a confirmation before running the cmdlet.

-Stream

The -Stream parameter is used to specify an alternate data stream for the content. If the stream does not exist, the clear-content cmdlet creates it. Wildcard characters are accepted.

It is a dynamic parameter that the Filesystem provider adds to the Clear-content. It works only in the file system drives.

Examples

Example 1: Delete the content from a specified file

PowerShell Clear-Content

The cmdlet, in this example, deletes the content from the File1.txt file in a specified location. The file is not deleted, but it is empty.

Example 2: Delete the content from all the files

PowerShell Clear-Content

The cmdlet, in this example, deletes the content of all the .txt files in the specified directory.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf