CmdID / PowerShell / Cmdlets / Invoke
Invoke-History
Runs commands from the session history. PowerShell reference
From the PowerShell reference
3 parameters
Aliases ihy, r
What it does
Runs commands from the session history. The Invoke-History cmdlet runs commands from the session history. You can pass objects representing the commands from Get-History to Invoke-History, or you can identify commands in the current history by using their Id number. To find the identification number of a command, use the Get-History cmdlet. The session history is managed separately from the history maintained by the PSReadLine module. Both histories are available in sessions where PSReadLine is loaded. This cmdlet only works with the session history. For more information see, about_PSReadLine.
Invoke-History [[-Id] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Run the most recent command in the history
Invoke-HistoryIdentifyRun the command that has a specified ID
Invoke-History -Id 132IdentifyRun the most recent command by using the command text
Invoke-History -Id get-prIdentifyRun a sequence of commands from the history
16..24 | ForEach-Object {Invoke-History -Id $_ }IdentifyExample 5
Get-History -Id 255 -Count 7 | ForEach-Object {Invoke-History -Id $_.Id}IdentifyIts page in the reference: Invoke-History.
Parameters
-IdSpecifies the Id of a command in the history. You can type the Id number of the command or the first few characters of the command.
If you type characters, Invoke-History matches the most recent commands first. If you omit this parameter, Invoke-History runs the last, or most recent, command. To find the Id number of a command, use the Get-History cmdlet.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.