Clear-History
Published: February 29, 2012
Updated: August 15, 2012
Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0
Clear-History
Aliases
The following abbreviations are aliases for this cmdlet:
- clhy
Syntax
Parameter Set: IDParameter Clear-History [[-Id] <Int32[]> ] [[-Count] <Int32> ] [-Newest] [-Confirm] [-WhatIf] [ <CommonParameters>] Parameter Set: CommandLineParameter Clear-History [[-Count] <Int32> ] [-CommandLine <String[]> ] [-Newest] [-Confirm] [-WhatIf] [ <CommonParameters>]
Detailed Description
The Clear-History cmdlet deletes commands from the command history, that is, the list of commands entered during the current session.
Without parameters, Clear-History deletes all commands from the session history, but you can use the parameters of Clear-History to delete selected commands.
Parameters
-CommandLine<String[]>
Deletes commands with the specified text strings. If you enter more than one string, Clear-History deletes commands with any of the strings.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
true |
-Count<Int32>
Clears the specified number of history entries, beginning with the oldest entry in the history.
If you use the Count and Id parameters in the same command, the cmdlet clears the number of entries specified by the Count parameter, beginning with the entry specified by the Id parameter. For example, if Count is 10 and Id is 30, Clear-History clears items 21 through 30 inclusive.
If you use the Count and CommandLine parameters in the same command, Clear-History clears the number of entries specified by the Count parameter, beginning with the entry specified by the CommandLine parameter.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
2 |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Id<Int32[]>
Deletes commands with the specified history IDs.
To find the history ID of a command, use Get-History.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
1 |
|
Default Value |
None |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Newest
Deletes the newest entries in the history. By default, Clear-History deletes the oldest entries in the history.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
False |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Confirm
Prompts you for confirmation before running the cmdlet.
|
Required? |
false |
|
Position? |
named |
|
Default Value |
false |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
|
Required? |
false |
|
Position? |
named |
|
Default Value |
false |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
-
None
You cannot pipe objects to Clear-History.
Outputs
The output type is the type of the objects that the cmdlet emits.
-
None
This cmdlet does not generate any output.
Notes
-
The session history is a list of the commands entered during the session. You can view the history, add and delete commands, and run commands from the history. For more information, see about_History.
Deleting a command from the history does not change the history IDs of the remaining items in the command history.
Examples
-------------------------- EXAMPLE 1 --------------------------
Deletes all commands from the session history.
PS C:\> clear-history
-------------------------- EXAMPLE 2 --------------------------
Deletes the commands with history IDs 23 and 25.
PS C:\> clear-history -id 23, 25
-------------------------- EXAMPLE 3 --------------------------
Deletes commands that include "help" or end in "command".
PS C:\> clear-history -command *help*, *command
-------------------------- EXAMPLE 4 --------------------------
Deletes the 10 newest commands from the history.
PS C:\> clear-history -count 10 -newest
-------------------------- EXAMPLE 5 --------------------------
Deletes the three oldest commands, beginning with the entry with ID 10.
PS C:\> clear-history -id 10 -count 3
Related topics