Runs commands from the session history
Syntax Invoke-History [[-id] string] [-whatIf] [-confirm] [CommonParameters] Key -id The ID number, or the first few characters of a command in the session history. -whatIf Describe what would happen if you executed the command without actually executing the command. -confirm Prompt for confirmation before executing the command. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
Standard Aliases for Invoke-History: r
To find the ID number of a command, use Get-History.
You can pipeline commands from Get-History directly to Invoke-History.
Examples
Run the last (most recent) command:
PS C:\> r
Run the most recent get- command in the session history:
PS C:\> invoke-history get-
Run commands 5 - 15 and 17: (separate multiple IDs with commas)
PS C:\> invoke-history (5..15), 17
“Spam will be a thing of the past in two years’ time” ~ Bill Gates, 2004
Related PowerShell Cmdlets:
Add-History - Add entries to the session history.
Get-History - Get a listing of the session history.
Equivalent bash command: history - Command Line history.