PowerShell Logo Small

Remove-Item



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

SYNOPSIS

Deletes the specified items.

SYNTAX


Remove-Item [-Path] <String[]> [-Credential [<PSCredential>]] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction
{SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Recurse] [-Stream [<System.String[]>]] [-Confirm] [-WhatIf]
[-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Remove-Item [-Credential [<PSCredential>]] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Recurse] [-Stream [<System.String[]>]] -LiteralPath <String[]> [-Confirm] [-WhatIf]
[-UseTransaction [<SwitchParameter>]] [<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, including files, directories,
registry keys, variables, aliases, and functions.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293896
Clear-Item
Copy-Item
Get-Item
Invoke-Item
Move-Item
New-Item
Remove-ItemProperty
Rename-Item
Set-Item
about_Providers

REMARKS

<

Examples


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

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



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 command does not delete
directories or files with no file name extension.






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

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



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 wildcard character (*) to specify
the contents of the current directory. It uses the Include and Exclude parameters to specify the files to delete.






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

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



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 give permission to delete it.
Without Force, you cannot delete read-only or hidden files.






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

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



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

Because the Recurse parameter in the Remove-Item cmdlet has a known issue (it might not delete all child directories or files, especially if the Include parameter is added
to the command), the command in this example uses the Get-ChildItem cmdlet to get the desired files, and then uses the pipeline 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 parameter 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 --------------------------

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



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