Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

Clear-History

Clear-History

system.management.automation.dll

Synopsis

Deletes entries from the command history.

Syntax

Clear-History [-Id] [-Count] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]

Clear-History [-Count] [-CommandLine] [-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 <SwitchParameter>

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 <SwitchParameter>

Prompts you for confirmation before running the cmdlet.

Aliases

None

Required?

false

Position

named

Default value

false

Accept pipeline input?

false

Accept wildcard characters?

false

-WhatIf <SwitchParameter>

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Aliases

None

Required?

false

Position

named

Default value

false

Accept pipeline input?

false

Accept wildcard characters?

false

Input Type

None

Return Type

None

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

Online Version
Add-History
Get-History
Invoke-History
about_History