PowerShell Logo Small

Invoke-History



This is the built-in help made by Microsoft for the command 'Invoke-History', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Runs commands from the session history.

SYNTAX


Invoke-History [[-Id] [<String>]] [-Confirm] [-WhatIf] [<CommonParameters>]



Search powershellhelp.space

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.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=289593
Add-History
Clear-History
Get-History
about_History

REMARKS

<

Examples


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

PS C:\>Invoke-History



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.










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

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 is optional, you can abbreviate this command as "Invoke-History 132",
"ihy 132", or "r 132".










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

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










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

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 the ForEach-Object cmdlet to run the Invoke-History command once for each
ID value.










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

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 the Get-History cmdlet to retrieve the commands. The pipeline
operator (|) passes the commands to Invoke-History, which executes them.