History

Commands

doshkey /h

Show command history

doskey /history

Displays the command history in the Command Prompt window.

Get-History

Shows the command history of PowerShell sessions.

Clear-History

Clears the command history in the current PowerShell session.

Get-History | Export-Clixml history.xml

Exports PowerShell command history to an XML file named "history.xml."

Import-Clixml history.xml | Add-History

Imports command history from an XML file named "history.xml" and appends it to the current session's history.

Retrieves security event log history using CIM (Common Information Model):

Get-CimInstance -ClassName Win32_NTLogEvent -Filter "Logfile='Security'"

Notes

Clear-History will clear the history, but leaves this command and the ID (command count).

There is also a file that still has your history located here:

C:\Users\<User>\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt

To actually clear the history:

  1. Run Clear-History

  2. Close PowerShell instances.

  3. Delete the ConsoleHost_history.txt file (location above).

Last updated

Was this helpful?