Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Invoke-History

Updated: October 17, 2013

Applies To: Windows PowerShell 4.0

Invoke-History

Runs commands from the session history.

Aliases

The following abbreviations are aliases for this cmdlet:

  • ihy, r

Syntax

Parameter Set: Default
Invoke-History [[-Id] <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed 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

-Id<String>

Identifies 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 (most recent) command. The parameter name ("id") is optional. To find the ID number of a command, use the Get-History cmdlet.


Aliases

none

Required?

false

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

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

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.String

    You can pipe a history ID to Invoke-History.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None

    Invoke-History 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 along 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).

Examples

-------------------------- EXAMPLE 1 --------------------------

This command runs the last (most recent) command in the session history. You can abbreviate this command as "r" (think "repeat" or "rerun"), the alias for Invoke-History.


PS C:\> Invoke-History

-------------------------- EXAMPLE 2 --------------------------

This command runs the command in the session history with ID 132. Because the name of the Id parameter is optional, you can abbreviate this command as "Invoke-History 132", "ihy 132", or "r 132".


PS C:\> Invoke-History -Id 132

-------------------------- EXAMPLE 3 --------------------------

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, beginning with the most recent commands. This command uses the Id parameter, but it omits the optional parameter name.


PS C:\> Invoke-History get-pr

-------------------------- EXAMPLE 4 --------------------------

This command runs commands 16 through 24. Because you can list only one ID value, the command uses the ForEach-Object cmdlet to run the Invoke-History command once for each ID value.


PS C:\> 16..24 | ForEach {Invoke-History -Id $_ }

-------------------------- EXAMPLE 5 --------------------------

This command runs the 7 commands in the history that end with command 255 (typically 249 through 255). It uses the Get-History cmdlet to retrieve the commands. The pipeline operator (|) passes the commands to Invoke-History, which executes them.


PS C:\> Get-History -Id 255 -Count 7 | Invoke-History

Related topics



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.