TheDeveloperBlog.com

Home | Contact Us

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

PowerShell Remove-Item

PowerShell Remove-Item 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 Remove-Item | PowerShell Remove file

The PowerShell Remove-Item cmdlet deletes one or more specified items. Because many providers support this cmdlet so that it can delete many different types of items, including files, folders, variables, registry keys, aliases, and functions.

Syntax

Remove-Item
[-Path<string[]>]
[-Confirm]
[-Filter <string>]
[-Recurse] 
[-Force]
[-Include <string[]>]
[-Exclude <string[]>]
[-Credential <pscredential>] 
[-WhatIf] 
[-UseTransaction] 
[-Stream <string[]>]  
[<CommonParameters>]

Remove-Item
[-LiteralPath <string[]>]
[-Filter <string>] 
[-Recurse]
[-Force]
[-Include <string[]>] 
[-Exclude <string[]>] 
[-Credential <pscredential>] 
[-WhatIf] 
[-Confirm] 
[-UseTransaction] 
[-Stream <string[]>]
[<CommonParameters>]

Parameters

-Path

The -Path parameter is used to specify a path of the items being removed. Wildcard characters are accepted.

-LiteralPath

The -LiteralPath parameter is used to specify a path to one or more locations. Its value is used exactly as it is typed. If the path includes the escape characters, enclose it in a single quotation mark. Single quotation mark tells the Windows PowerShell that it should not interpret any character as an escape sequence. There is no character in the cmdlet, which is interpreted as a wildcard.

-Confirm

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

-Filter

The -Filter parameter specifies a filter to qualify the -Path parameter. The FileSystem provider is the only PowerShell provider that supports the uses of filters. 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.

-Recurse

The -Recurse parameter indicates that this cmdlet deletes the items in the given location and all the child items of the locations. When this parameter is used with the -Include parameter, it might not delete all subfolders or all child items.

-Force

The -Force parameter forces the cmdlet to delete those items which cannot be changed, such as hidden, read-only files, aliases, or variables. It cannot remove constant variables or aliases. Even using the -Force parameter, the cmdlet cannot override security permissions.

-Include

The items that this cmdlet includes in the operation are 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. The -Exclude parameter is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character '*' is used to specify the contents of the C: directory.

-Exclude

The items that this cmdlet excludes in operation are specified as a string array. The value of -Exclude parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. Wildcard characters are accepted. The -Exclude parameter is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character '*' is used to specify the contents of the C: directory.

-WhatIf

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

-Stream

The -Stream parameter is a dynamic parameter that the FileSystem provider adds to Remove-Item cmdlet. It works only in the file system drives and introduced in Windows PowerShell 3.0.

Examples

Example1: Remove a specified file in current drive

PowerShell Remove-Item

The cmdlet, in this example, deletes a given s.txt file in the current drive.

Example 2:Delete the files that have a .txt file name extension

PowerShell Remove-Item

The cmdlet in this example deletes all of the files that have .txt extension from the D:\PowerShell folder.

Example 3: Delete the document files in the current folder

PowerShell Remove-Item

The cmdlet in this example deletes all the files that have a .doc file name extension and a name that does not include 1 from the current folder. It uses the wildcard character '*' to specify the current. And it uses the -Include and -Exclude parameters to specify the files to delete.






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