Tuesday, May 17, 2016

PowerShell cmdlet of the Day : Invoke-History

 

You might be thinking, what "Invoke-History" does?

Actually it re-run the command which you run before running "Invoke-History", in simple words , this cmdlet executes the latest command which you run in PowerShell console.

Aman Dhally, Manya Kaur

In the above screenshot you can see, that it runs the last executed command. You might be thinking, it's not helpful, you can re-run the last run command by pressing UP-Arrow and then hit enter, yes you are right, But (Sorry! there is always a BUT!).

In my previous post, when we run the Get-History cmdlet and I had mentioned that in the out of the Get-History cmdlet the property  ID is quite important, in Invoke-History you can use the -ID parameter to run the specific command which is stored in the History :D .

Aman Dhally, Manya Kaur

In the above screenshot the Invoke-History will execute the command which have the ID number 17 in History.

Cool! I am right ;)

With Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel
for PowerShell video tutorials. You can download all of my scripts from “Microsoft
TechNet Gallery”.

No comments:

Post a Comment