Export (0) Print
Expand All
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

Using the Invoke-History Cmdlet

Re-running a Previous Command

The Invoke-History cmdlet enables you to re-execute a Windows PowerShell command simply by specifying the ID number assigned to that command. (How can you determine the ID number assigned to a command? Use the Get-History cmdlet.) For example, suppose you issued a fairly complicated command at the beginning of your Windows PowerShell session, a command you now need to issue again. Instead of retyping the command (and running the risk of typing it incorrectly), run Get-History to determine the command ID (say, 3). Then simply call Invoke-History followed by the ID number:



Invoke-History 3

The Invoke-History cmdlet accepts only a single ID. What if you’d like to execute two or more previous commands, in rapid-fire succession? In that case, simply issue a pair of Invoke-History commands, separating the two using a semi-colon:



Invoke-History 3;Invoke-History 4

Invoke-History Aliases
  • ihy

  • r

Related Links

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.