Clear-History

Deletes entries from the command history.
Clear-History [[-Id] [<Int32[]>]] [[-Count] [<Int32>]] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]
Clear-History [[-Count] [<Int32>]] [-CommandLine [<String[]>]] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>]

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[]>]

Specifies commands that this cmdlet deletes. If you enter more than one string, Clear-History deletes commands that have any of the strings.

-Count [<Int32>]

Specifies the number of history entries that this cmdlet clears, starting 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, starting 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, starting with the entry specified by the CommandLine parameter.

-Id [<Int32[]>]

  • Default value is None

Specifies the history IDs of commands that this cmdlet deletes.

To find the history ID of a command, use the Get-History cmdlet.

-Newest [<SwitchParameter>]

Indicates that this cmdlet deletes the newest entries in the history. By default, Clear-History deletes the oldest entries in the history.

-Confirm [<SwitchParameter>]

  • Default value is false

Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdlet.

-WhatIf [<SwitchParameter>]

  • Default value is false

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

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

None

You cannot pipe objects to this cmdlet.

Outputs

None

This cmdlet does not generate any output.

Examples
  1. Delete all commands:
    PS C:> Clear-History
    

    This command deletes all commands from the session history.

  2. Delete commands by using history IDs:
    PS C:> Clear-History -Id 23, 25
    

    This command deletes the commands that have history IDs 23 and 25.

  3. Delete specific commands:
    PS C:> Clear-History -Command *help*, *command
    

    This command deletes commands that include “help” or end in “command”.

  4. Delete the newest commands:
    PS C:> Clear-History -Count 10 -Newest
    

    This command deletes the 10 newest commands from the history.

  5. Delete the oldest commands:
    PS C:> Clear-History -Id 10 -Count 3
    

    This command deletes the three oldest commands, starting with the entry with ID 10.

Additional 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.
Related Links

Add-History
Get-History
Invoke-History