How to View, Save, and Clear Your PowerShell and Command Prompt History
By Timothy Tibbetts |
Both the Command Prompt and PowerShell can show you the history of all commands during the current session. In this guide, we show you not only how to how to view your history but other options including how to clear and save your current Command Prompt or PowerShell session.
Command Prompt
The Command Prompt history can be viewed by typing in doskey /history, or our favorite quick way, pressing the F7 button. If you use the F7 method, press the ESC key to close.

You can save your history by typing in doskey /HISTORY > SampleHistory.txt replacing. TXT with the supported file types including TXT, HTML, CSV or RTF.
Clearing your current history is as simple as closing the Command Prompt, since, as we mentioned, only your current session is saved. You can also press Alt+F7 to clear your history without closing the Command Prompt.
-=- Advertisement -=-
PowerShell
PowerShell, as always, is better and features many more options. One of the best thing about PowerShell is that it saves the last 4,096 typed commands automatically in %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt. Unlike the Command Prompt, this list is saved even if you close PowerShell.
You can see all the command from your current session only by typing in Get-History. Optionally, you can type in Get-History | Format-List -Property * to see more information including the start and end times and command status.

You can also search for a command by typing in CTRL+R (reverse search) or CTRL+S (forward search) and begin typing in the command you're looking for.
To clear your history or see the options we mentioned, you can type in Get-PSReadlineKeyHandler | ? {$_.function -like '*hist*'}. Like the Command Prompt, Alt+F7 also works will if you want to clear the current session history.

Unlike the Command Prompt, we discussed where your PowerShell history is saved. If you'd like to clear that text file, type in Remove-Item (Get-PSReadlineOption).HistorySavePath. ConsoleHost_history.txt will be deleted and recreated the next time you type a command into Powershell.
You can also export your current session to an XML file by typing in Get-History | Export-Clixml -Path c:\ps\commands_hist.xml.
Similar:
The Ultimate List of Every Known Command Prompt and PowerShell Commands
PowerShell and Command Prompt 101
How-To Run PowerShell or the Command Prompt as Administrator
What's the Difference Between PowerShell and PowerShell Core?
PowerShell Data Execution Policies Explained
comments powered by Disqus
Command Prompt
The Command Prompt history can be viewed by typing in doskey /history, or our favorite quick way, pressing the F7 button. If you use the F7 method, press the ESC key to close.

You can save your history by typing in doskey /HISTORY > SampleHistory.txt replacing. TXT with the supported file types including TXT, HTML, CSV or RTF.
Clearing your current history is as simple as closing the Command Prompt, since, as we mentioned, only your current session is saved. You can also press Alt+F7 to clear your history without closing the Command Prompt.
PowerShell
PowerShell, as always, is better and features many more options. One of the best thing about PowerShell is that it saves the last 4,096 typed commands automatically in %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt. Unlike the Command Prompt, this list is saved even if you close PowerShell.
You can see all the command from your current session only by typing in Get-History. Optionally, you can type in Get-History | Format-List -Property * to see more information including the start and end times and command status.

You can also search for a command by typing in CTRL+R (reverse search) or CTRL+S (forward search) and begin typing in the command you're looking for.
To clear your history or see the options we mentioned, you can type in Get-PSReadlineKeyHandler | ? {$_.function -like '*hist*'}. Like the Command Prompt, Alt+F7 also works will if you want to clear the current session history.

Unlike the Command Prompt, we discussed where your PowerShell history is saved. If you'd like to clear that text file, type in Remove-Item (Get-PSReadlineOption).HistorySavePath. ConsoleHost_history.txt will be deleted and recreated the next time you type a command into Powershell.
You can also export your current session to an XML file by typing in Get-History | Export-Clixml -Path c:\ps\commands_hist.xml.
Similar:
comments powered by Disqus