SysAdmins
Now Reading
How to clear Powershell history (done right!)
0

How to clear Powershell history (done right!)

You might find youserlf in a situation where you need to clear Powershell command history. For example, for us it was needed because we needed to prepare templates for virtual machines deployment and we needed to activate a specific software before finalizing the template.

Unfortunately you need to type a command to enter the code and activate the software and those templates could be used by our customers that might be able to retrieve the correct code by simply striking arrow-up. If you look for a solution you will find that Powershell has a specific command to do that:

Clear-History

However, you might find that this won’t solve your problem. Some history gets cancelled and some don’t or sometimes nothing at all gets removed and all of your history is still available to anyone logging using that account.

Turned out that there’s a way to check actually where Powershell stores your history. Just issue this command:

PS C:\Users\Administrator> (Get-PSReadlineOption).HistorySavePath
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

The result is the location of the history file. Just edit this file and remove those lines you don’t want other users to access.

Neat trick but actually we’re not sure why the dedicated command is not working as expected.

What's your reaction?
Love It
100%
Interested
0%
Meh...
0%
What?
0%
Hate it
0%
Sad
0%
Laugh
0%
Sleep
0%
Wow !
0%
About The Author
The Server-Side Technology Staff
You must unlearn what you have learned.

Leave a Response