Command and PowerShell History
To view the command history in PowerShell, you have several options:
1. Using Get-History
cmdlet
- Get-Command History: Use
Get-History
in PowerShell to view your session’s command history.
- Retrieve Command by ID: You can re-run a command by its history ID:
- Exporting Command History: Save the command history to a file for future reference.
2. Using h
alias
- The
Get-History
cmdlet has a short alias,h
, that you can use as a shorthand:
h
PowerShell saves command history across sessions in a file. You can open this file to view your past commands. The default location for this file is:
- Windows PowerShell:
C:\Users\<YourUserName>\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
- PowerShell (Core):
C:\Users\<YourUserName>\AppData\Roaming\Microsoft\PowerShell\PSReadLine\ConsoleHost_history.txt
You can open this file in any text editor or view its contents using PowerShell:
Or for PowerShell Core:
This allows you to view a persistent history across multiple sessions.
5. Clear Command History
- Clear PowerShell History for Current Session:
- Delete Persistent PowerShell History: Locate the history file and delete or clear it:
References:
Total 0 Votes
0
0