MSFTNEXT

Export PowerShell Command History To a File

How to Export PowerShell Command History to a File

PowerShell is saving every single command you execute in its console. Its history is limited by 32767 items, which is a huge number. It is very convenient, as it allows going to any of your previous commands to execute it one more time, or modify and run it.

PowerShell is a modern version of the Windows command prompt. Its basic commands can be extended with a huge set of ready-to-use cmdlets. Also, it allows using .NET framework/C# programming language in various scenarios. If you have skill to write scripts, you can create some very powerful ones to automate the operating system. It can be a handy tool for regular users too to perform administrative and maintenance tasks.

Using PowerShell and its cmdlets can be very helpful. It often extends existing functionality of Windows 10, and even adds features that are missing by default. Once you learn all the PowerShell cmdlets, automating Windows is really easy.

You can walk through your PowerShell command history by using the Up and Down arrow keys in the command history. You may also be interested in saving the entire history to a text file, so you can read and process it in a convenient way.

This post will show you how to export the PowerShell command history to a file.

To Export PowerShell Command History to a File

  1. Open PowerShell.
  2. Type or copy-paste the following command: (Get-PSReadlineOption).HistorySavePath, and hit the Enter key.
  3. The command history will be saved to the file C:\Users\Your user name\AppData\Roaming\Microsoft\Windows\
    PowerShell\PSReadLine\ConsoleHost_history.txt.

Now you should have a list of the full history of your previously entered PowerShell commands.

Note that PowerShell command history does not distinguish between the command list for regular and elevated consoles. So everything you type in PowerShell running as Administrator will appear in the history of a regular PowerShell window. After exporting the history as shown above, the text file will also not clearly indicate whether the command was executed with elevated privileges or not.

Looks like you've read the post to the end. If you enjoyed it, please share it. You would greatly help our blog to grow!
Exit mobile version