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:
1 |
%userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt |
or use this command to get the full path:
1 |
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:
1 |
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:
1 |
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