PowerShell - Where is the command history stored?

·

1 min read

Every command you type into a PowerShell console is recorded in a single file in the current user's app data directory. This is useful when you need to refer back to a command you entered but it can be security risk if you've entered sensitive data in plain text (like passwords or user data). In those cases try to use secure objects like PSCredential for usernames and passwords.

You can find the file here:

C:\\Users\\%username%\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadline

If you want to disable saving your commands to this file you can add the following to either your PowerShell profile.ps1 file to permanently disable it or for just the current console session simply type it in to your console.

Set-PSReadlineOption -HistorySaveStyle SaveNothing

More information available here:

https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-6