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.
- Get-History : This command shows the list of the commands entered during the current session.
- Invoke-History : This command executes specific command from the session history. For example “Invoke-History 4” will execute 4th command in the list.
- Add-History : This command appends entries to the session history.
- 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