Deletes entries from the command history.

Syntax

  Copy Code
Clear-History [[-Id] <Int32[]>] [[-Count] <int>] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]

Clear-History [[-Count] <int>] [-CommandLine <string[]>] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]

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.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Count <int>

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.

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.

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.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before executing the command.

Required?

false

Position?

named

Default Value

none

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

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This command supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, OutBuffer, OutVariable, WarningAction, and WarningVariable. For more information, see about_CommonParameters.

Inputs and Outputs

The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet returns.

Inputs

None

You cannot pipe objects to Clear-History.

Outputs

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.

Example 1

  Copy Code
C:\PS>clear-history

Description

-----------

Deletes all commands from the session history.

Example 2

  Copy Code
C:\PS>clear-history -id 23, 25

Description

-----------

Deletes the commands with history IDs 23 and 25.

Example 3

  Copy Code
C:\PS>clear-history -command *help*, *command

Description

-----------

Deletes commands that include "help" or end in "command".

Example 4

  Copy Code
C:\PS>clear-history -count 10 -newest

Description

-----------

Deletes the 10 newest commands from the history.

Example 5

  Copy Code
C:\PS>clear-history -id 10 -count 3

Description

-----------

Deletes the three oldest commands, beginning with the entry with ID 10.

See Also