NAME
Invoke-History
SYNOPSIS
Runs commands from the session history.SYNTAX
Invoke-History [[-Id]
] [-Confirm] [-WhatIf] [ ] DESCRIPTION
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.
PARAMETERS
-Confirm [
Prompts you for confirmation before running the cmdlet. Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false] -Id
Specifies 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. Required? false Position? 0 Default value NoneAccept pipeline input? True (ByPropertyName)
Accept wildcard characters? false-WhatIf [
Shows what would happen if the cmdlet runs. The cmdlet is not run. Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false] This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). INPUTS
System.String You can pipe a history ID to this cmdlet.OUTPUTS
NoneThis cmdlet does not generate any output, but output might be generated by the commands that Invoke-History
runs.NOTES
* The session history is a list of the commands entered during the session together with the ID. The session
history represents the order of execution, the status, and the start and end times of the command. As you enter each command, Windows PowerShell adds it to the history so that you can reuse it. For more information about the session history, see about_History (http://go.microsoft.com/fwlink/?LinkID=113233).You can also refer to Invoke-History by its built-in aliases, "r" and "ihy". For more information, see
about_Aliases (http://go.microsoft.com/fwlink/?LinkID=113207).
*
Example 1: Run the most recent command in the history
PS C:\>Invoke-History
This command runs the last, or most recent, command in the session history. You can abbreviate this command as`r`, the alias for Invoke-History .
Example 2: Run the command that has a specified ID
PS C:\>Invoke-History -Id 132
This command runs the command in the session history with ID 132. Because the name of the Id parameter isoptional, you can abbreviate this command as the following: `Invoke-History 132`, `ihy 132`, or `r 132`.
Example 3: Run the most recent command by using the command text
PS C:\>Invoke-History -ID get-pr
This command runs the most recent Get-Process command in the session history. When you type characters for the Id
parameter, Invoke-History runs the first command that it finds that matches the pattern, starting with the most
recent commands.Example 4: Run a sequence of commands from the history
PS C:\>16..24 | ForEach {Invoke-History -Id $_ }
This command runs commands 16 through 24. Because you can list only one ID value, the command uses theForEach-Object cmdlet to run the Invoke-History command one time for each ID value.
Example 5: Run several commands by using Get-History
PS C:\>Get-History -Id 255 -Count 7 | Invoke-History
This command runs the 7 commands in the history that end with command 255, typically 249 through 255. It uses theGet-History cmdlet to retrieve the commands. The pipeline operator (|) passes the commands to Invoke-History ,
which runs them.RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821494Add-History
Clear-History
Get-History