Add History - PowerShell
Overview
Add-History is a PowerShell command that adds a command to the PowerShell history. This allows you to recall and reuse previously executed commands, streamlining your workflow and enhancing productivity.
Syntax
Add-History [-Command] <String> [-NoDate] [-NoDuplication] [-Tags <String[]>] [-HistoryId <Int32>]
Options/Flags
- -Command: Specifies the command to add to the history. Required.
 - -NoDate: Omits the date from the history entry.
 - -NoDuplication: Prevents duplicate entries from being added to the history.
 - -Tags: Adds specified tags to the history entry. Supports multiple tags separated by commas.
 - -HistoryId: Sets a specific ID for the history entry.
 
Examples
- Add a command to the history:
 
Add-History Get-Date
- Add a command with tags:
 
Add-History -Command Update-Database -Tags "Database,Update"
- Suppress date from history entry:
 
Add-History -Command "echo Hello" -NoDate
Common Issues
- Incorrectly formatted commands: Ensure the command specified in 
-Commandis valid and formatted correctly. - History size limitations: PowerShell history has a size limit. Consider using 
Clear-HistoryorSet-HistorySizeto manage history size. - Duplicate entries: The 
-NoDuplicationflag can prevent duplicate entries, but it may be necessary to manually remove them usingGet-History. 
Integration
- Use 
Get-Historyto retrieve history entries based on various criteria. - Pipe history entries to 
Invoke-Historyto re-execute them. - Employ the 
-HistoryIdoption to integrate with custom scripts or tools that manage history records.