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:

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:

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:

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

 

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

About Nicolas 230 Articles
I work as a System Engineer, based in Switzerland with a primary focus on Microsoft technologies. I have 7 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 "MCSA: Windows Server 2012" and "Administering & Deploying SCCM" certified.