Remove content from a variable, or alias. Remove a registry entry.
Clearing an alias will also delete the alias, clearing a variable will empty the variable contents.

      Clear-item [[-path] | [-literalPath] ] string[]
         [-include string[]] [-exclude string[] ]
            [-filter string] [-force] [-credential PSCredential] [-confirm]
               [-whatIf] [-UseTransaction] [CommonParameters]

   -Path string
       The paths to the items from which content is deleted.
       Wildcards are permitted.

   -LiteralPath string
       Like Path above, only the value is used exactly as typed.
       No characters are interpreted as wildcards. If the path includes any
       escape characters then enclose the path in single quotation marks.

   -Include string
       Clear only the specified items from the Path. e.g. "May*"

   -Exclude string
       Omits the specified items from the Path e.g. "*SS64*"

   -Filter string
       A filter in the provider's format or language. 
       The exact syntax of the filter (wildcard support etc) depends on the provider.
       Filters are more efficient than -include/-exclude, because the provider
       applies the filter when retrieving the objects, rather than having 
       PowerShell filter the objects after they are retrieved.

       Override any restrictions that would prevent the command from succeeding,
       apart from security settings. e.g. Force will create file path directories
       or override a files read-only attribute, but will not change file permissions.

   -Credential PSCredential
       Uses a credential to validate access to the file. Credential represents
       a user-name, such as "User01" or "Domain01\User01", or a PSCredential
       object, such as the one retrieved using Get-Credential.
       This parameter appears, but it is not yet supported in any PowerShell core 
       cmdlets or providers.

       Prompt for confirmation before executing the command.

       Describe what would happen if you executed the command without actually
       executing the command.
       Include the command in the active transaction.

Standard Aliases for Clear-Item: cli


Delete the content of a MyTestVariable:

PS C:> clear-item Variable:MyTestVariable
PS C:> Set-location Variable:
PS Variable:\> clear-item MyTestVariable

Remove the aliases: ss64demo1, ss64demo2:

PS C:> clear-item Alias:ss64* -include *demo*

Remove all the registry entries under : hklm\Software\SS64\DemoKey:

PS C:> clear-item registry::HKLM\Software\SS64\DemoKey

"All of Western logic is based upon the law of contradiction -- if two things contradict, then at least one of them is false. But Islamic logic is dualistic; two things can contradict each other and both are true" ~ Bill Warner

Related PowerShell Cmdlets

Clear-Content is similar to Clear-Item, but works on files, instead of aliases and variables.
Remove-Item - Remove an item.

Copyright © 1999-2024
Some rights reserved