Managing History of Powershell Commands

When you type command in the Powershell, all those commands are saved in the history. You can use below commands to manage history of commands.

  1. Get-History : This command shows the list of the commands entered during the current session.
  2. Invoke-History : This command executes specific command from the session history. For example “Invoke-History 4” will execute 4th command in the list.
  3. Add-History :  This command appends entries to the session history.
  4. Clear-History : This command removes entries from the command history.

We can export all commands in the history to a file using below syntax.

> Get-History | Export-Clixml “history.xml”

We can import all commands from the file using below syntax.

> Import-Clixml “history.xml” | Add-History

You may also like...