PoshTip #50 – Working With PowerShell History

Have you ever desperately looked for a PowerShell command that you typed and not saved… Well great news! PowerShell has a big memory and it can help you to retrieve this command you have entered. Even if you closed the PowerShell console or rebooted your machine, PowerShell keeps the history.

You can find the full history in the following text file:


or use this command to get the full path:

PS > (Get-PSReadlineOption).HistorySavePath

More information about PSReadline module: here

OK, now just imagine that you have entered a password in a previous command, you probably don’t want another user can read it. So you must clear the history. To perform this task, just use the following command to remove the file:

PS > Remove-Item (Get-PSReadlineOption).HistorySavePath

Be careful, because the Clear-History cmdlet will not clear the history! It will only clear the history you can see with Get-History cmdlet.

Do you want to set another location for this file?

Use the following command with -HistorySavePath parameter to specify a new path:

PS > Set-PSReadlineOption –HistorySavePath C:\Temp\History.txt

Note: You can easily deploy the same history file on many machines.


Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.