CmdID

CmdID / PowerShell / Cmdlets / Clear

Clear-History

Deletes entries from the PowerShell session command history. PowerShell reference

From the PowerShell reference 6 parameters Alias clhy

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Deletes entries from the PowerShell session command history. Clear-History deletes the command history from a PowerShell session. Each PowerShell session has its own command history. To display the command history, use the Get-History cmdlet. By default, Clear-History deletes the entire command history from a PowerShell session. You can use parameters with Clear-History to delete selected commands. Clear-History does not clear the PSReadLine command history file. The PSReadLine module stores a history file that contains every PowerShell command from every PowerShell session. From a PowerShell prompt, use the up and down arrows on your keyboard to scroll through the command history. To display the PSReadLine configuration for command history, use Get-PSReadLineOption. PSReadLine shipped with PowerShell 5.0 and above. For more information, see about_PSReadLine.

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

Delete the command history from a PowerShell session

Get-HistoryIdentify

Delete the newest commands

Get-HistoryIdentify

Delete commands that match specific criteria

Get-HistoryIdentify

Delete commands by Id number

Get-HistoryIdentify

Delete commands by Id number and count

Get-HistoryIdentify

Its page in the reference: Clear-History.

Parameters

6 in the PowerShell reference
-CommandLineDeletes command history from a PowerShell session. The string must be an exact match or use wildcards to match commands in the PowerShell session history displayed by Get-History. If you enter more than one string, Clear-History deletes commands that match any of the strings. The CommandLine parameter can be used with Count. For strings with a space, use single quotations. For more information, see about_Quoting_Rules.
-CountSpecifies the number of history entries that Clear-History deletes. Commands are deleted in order, beginning with the oldest entry in the history. The Count and Id parameters can be used together. The Count parameter specifies the number of commands to delete, inclusive of the specified Id. Beginning at the specified Id, commands are deleted in reverse sequential order. For example, if the Id is 30 and the Count is 10, Clear-History deletes items 21 through 30. The Count and CommandLine parameters can be used together. Count specifies the number of commands to delete that match CommandLine parameter value. The commands are deleted in sequential order.
-IdSpecifies the command history Id that Clear-History deletes. To display Id numbers, use the Get-History cmdlet. The Id numbers are sequential and commands keep their Id number throughout a PowerShell session. The Id parameter can be used with Count and Newest.
-NewestWhen the Newest parameter is used, Clear-History deletes the newest entries in the history. By default, Clear-History deletes the oldest entries in the history. The Newest parameter can be used with Id and Count. The Count parameter specifies the number of commands to delete, inclusive of the specified Id. Beginning at the specified Id, commands are deleted in sequential order. For example, if the Id is 30 and the Count is 10, Clear-History deletes items 30 through 39.
-ConfirmPrompts you for confirmation before running the Clear-History cmdlet.
-WhatIfShows what would happen if the Clear-History cmdlet runs. The cmdlet is not run.