powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Remove-Item



NAME
Remove-Item

SYNOPSIS
Deletes the specified items.

SYNTAX
Remove-Item [-LiteralPath] [-Credential ] [-Exclude ] [-Filter ] [-Force
] [-Include ] [-Recurse] [-Confirm] [-WhatIf] [-UseTransaction] []

Remove-Item [-Path] [-Credential ] [-Exclude ] [-Filter ] [-Force] [-Inc
lude ] [-Recurse] [-Confirm] [-WhatIf] [-UseTransaction] []


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


PARAMETERS
-Credential
Specifies a user account that has permission to perform this action. The default is the current user.

Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated
by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

This parameter is not supported by any providers installed with Windows PowerShell.

Required? false
Position? named
Default value
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-Exclude
Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pa
ttern, such as "*.txt". Wildcards are permitted.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Filter
Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path paramet
er. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficie
nt than other parameters, because the provider applies them when retrieving the objects, rather than having Win
dows PowerShell filter the objects after they are retrieved.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Force []
Allows the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files or read-o
nly aliases or variables. The cmdlet cannot remove constant aliases or variables. Implementation varies from p
rovider to provider. For more information, see about_Providers. Even using the Force parameter, the cmdlet cann
ot override security restrictions.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Include
Deletes only the specified items. The value of this parameter qualifies the Path parameter. Enter a path elemen
t or pattern, such as "*.txt". Wildcards are permitted.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-LiteralPath
Specifies a path to the items being removed. Unlike Path, the value of LiteralPath is used exactly as it is typ
ed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single qu
otation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequenc
es.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-Path
Specifies a path to the items being removed. Wildcards are permitted. The parameter name ("-Path") is optional.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-Recurse []
Deletes the items in the specified locations and in all child items of the locations.

The Recurse parameter in this cmdlet does not work properly.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm []
Prompts you for confirmation before executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf []
Describes what would happen if you executed the command without actually executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-UseTransaction []
Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
For more information, see about_Transactions.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.String
You can pipe a string that contains a path (but not a literal path) to Remove-Item.


OUTPUTS
None
This cmdlet does not return any output.


NOTES


You can also refer to Remove-Item by any of its built-in aliases, "del", "erase", "rmdir", "rd", "ri", or "rm".
For more information, see about_Aliases.

The Remove-Item cmdlet is designed to work with the data exposed by any provider. To list the providers availab
le in your session, type "Get-PsProvider". For more information, see about_Providers.


-------------------------- 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 com
mand specifies a dot, the command 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 wildcard character (*) to specify the contents of the current directory. It uses the Inclu
de 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 u
ses the Force parameter to give 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 desire
d files, and it 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 dir
ectory. It uses the Include parameter to specify the CSV file type, and it uses the Recurse parameter to make the r
etrieval recursive.

If you try to specify the file type in the path, such as "-path *.csv", the cmdlet interprets the subject of the se
arch 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 r
emove 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 yo
u omit the Recurse parameter, you are prompted to confirm that you want to delete the contents of the key.






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