PowerShell Logo Small


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


Deletes the contents of an item, but does not delete the item.


Clear-Item [-Path] <String[]> [-Credential [<PSCredential>]] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction
{SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]]
Clear-Item [-Credential [<PSCredential>]] [-Exclude [<String[]>]] [-Filter [<String>]] [-Force] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] -LiteralPath <String[]> [-Confirm] [-WhatIf] [-UseTransaction [<SwitchParameter>]]

Search powershellhelp.space


The Clear-Item cmdlet deletes the value of an item, but it does not delete the item. For example, Clear-Item can delete the value of a variable, but it does not delete the
variable. The value that used to represent a cleared item is defined by each Windows PowerShell provider. Clear-Item is similar to Clear-Content, but it works on aliases
and variables, instead of files.



Online Version: http://go.microsoft.com/fwlink/p/?linkid=289800




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

PS C:\>Clear-Item Variable:TestVar1
PS C:>Set-location Variable:PS Variable:\> Clear-Item Testvar1

This command deletes the value of the variable, Testvar1. The variable remains and is valid, but its value is set to null. The variable name is prefixed with "Variable:" to
indicate the Windows PowerShell Variable provider.

The alternate commands show that, to get the same result, you can switch to the Windows PowerShell Variable: drive and then run the Clear-Item command.

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

PS C:\>Clear-Item Alias:log* -Include *1* -Exclude *3* -Whatif
What if: Performing operation "Clear Item" on Target "Item: log1".

This command asks Windows PowerShell what would happen if you executed the command, "clear-item alias:log* -include *1* -exclude *3". In response, Windows PowerShell
explains that it would delete the value of the log1 alias, but the command would not have any effect on the log, log2, or log13 aliases. Because the Alias provider does not
permit an alias without a value, when you clear an alias, you also delete the alias.

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

PS C:\>Clear-Item HKLM:\Software\MyCompany\MyKey -Confirm

This command deletes all registry entries in the MyKey subkey, but only after prompting you to confirm your intent. It does not delete the MyKey subkey or affect any other
registry keys or entries. You can use the Include and Exclude parameters to identify particular registry keys, but you cannot use them to identify registry entries. To
delete particular registry entries, use the Remove-ItemProperty cmdlet. To delete the value of a registry entry, use the Clear-ItemPropertycmdlet.