Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
TheTwist

Powershell history

Recommended Posts

Posted · Original PosterOP

Is there a way to turn off history (using the up arrow)  from previous commands on a new Window in Powershell?

 

For example when I close Powershell and I open a new window, those commands are not available?

 

Link to post
Share on other sites

I'm not sure there's a setting to do this so that every PowerShell instance will drop the contents of its session history automatically...

 

However, you can do this manually. Your PowerShell history is actually stored in a text file. You can find the location of your text file by entering this:

 

(Get-PSReadlineOption).HistorySavePath

 

You can simply use the Remove-Item cmdlet to delete the file. (Or just do it in the file explorer)

 

Remove-Item (Get-PSReadlineOption).HistorySavePath

 

After entering this command, the history file is delete, and the next command entered in PowerShell will be saved to that file (If you deleted it with that command then a new file is created). This is just an ordinary text file with each line being a PowerShell command entered. You can go through and pick and choose and delete certain commands and then save the file (I guess if you wanted to be malicious and hide that you ran some command, but still have the rest of the history show up). You can even just go ahead and enter a new line of random text and save the file. In your next PowerShell instance you can Up Arrow and it will display the text you entered in the text file even if it was never entered in PowerShell, since all it does is parse through the lines of that file.

 

Anyways, maybe some of this info was helpful to you, but I could not find anyway (like a setting) to drop all history changes upon exiting PowerShell automatically. However, if you just want to delete some, or all, of your history, it can be done as shown.


Current PC build: [CPU: Intel i7 8700k] [GPU: GTX 1070 Asus ROG Strix] [Ram: Corsair LPX 32GB 3000MHz] [Mobo: Asus Prime Z370-A] [SSD: Samsung 970 EVO 500GB primary + Samsung 860 Evo 1TB secondary] [PSU: EVGA SuperNova G2 750w 80plus] [Monitors: Dual Dell Ultrasharp U2718Qs, 4k IPS] [Case: Fractal Design R5]

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×