PowerShell Logo Small

Remove-Item



This is the built-in help made by Microsoft for the command 'Remove-Item', 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 specified items.

SYNTAX


Remove-Item [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Recu
rse] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]
Remove-Item [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Recurse] [-
Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Remove-Item cmdlet deletes one or more items. Because it is supported by many providers, it can delete many different types of items, includi
ng files, directories, registry keys, variables, aliases, and functions.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113373
about_Providers
Clear-Item
Copy-Item
Get-Item
Invoke-Item
Move-Item
New-Item
Remove-ItemProperty
Rename-Item
Set-Item

REMARKS

<

Examples


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

C:\PS>remove-item C:\Test\*.*



Description
-----------
This command deletes all of the files with names that include a dot (.) from the C:\Test directory. Because the command specifies a dot, the comm
and does not delete directories or files with no file name extension.








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

C:\PS>remove-item * -include *.doc -exclude *1*



Description
-----------
This command deletes from the current directory all files with a .doc file name extension and a name that does not include "1". It uses the wildc
ard character (*) to specify the contents of the current directory. It uses the Include and Exclude parameters to specify the files to delete.








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

C:\PS>remove-item -path C:\Test\hidden-RO-file.txt -force



Description
-----------
This command deletes a file that is both hidden and read-only. It uses the Path parameter to specify the file. It uses the Force parameter to giv
e permission to delete it. Without Force, you cannot delete read-only or hidden files.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-childitem * -include *.csv -recurse | remove-item



Description
-----------
This command deletes all of the CSV files in the current directory and all subdirectories recursively.

Because the Recurse parameter in this cmdlet is faulty, the command uses the Get-Childitem cmdlet to get the desired files, and it uses the pipel
ine operator to pass them to the Remove-Item cmdlet.

In the Get-ChildItem command, the Path parameter has a value of *, which represents the contents of the current directory. It uses the Include pa
rameter to specify the CSV file type, and it uses the Recurse parameter to make the retrieval recursive.

If you try to specify the file type in the path, such as "-path *.csv", the cmdlet interprets the subject of the search to be a file that has no
child items, and Recurse fails.








-------------------------- EXAMPLE 5 --------------------------

C:\PS>remove-item hklm:\software\mycompany\OldApp -recurse



Description
-----------
This command deletes the OldApp registry key and all of its subkeys and values. It uses the Remove-Item cmdlet to remove the key. The path is spe
cified, but the optional parameter name (Path) is omitted.

The Recurse parameter deletes all of the contents of the OldApp key recursively. If the key contains subkeys and you omit the Recurse parameter,
you are prompted to confirm that you want to delete the contents of the key.