PowerShell Quick Tip – Get-History and the Pipeline
- Posted by Cláudio Silva
- On May 26, 2017
- 2 Comments
- PowerShell; Get-History;
On the last week I went to Anthony Nocentino’s (b | t) precon “Open Source Powershell On Linux – Skills To Manage Your Heterogenous Data Center” at TugaIT conference which I recommend (both the precon and the conference 😉 ).
While we were running some commands we talked about Get-History cmdlet.
For those who don’t know
this cmdlet lists all the commands that you already ran on the current session.
Here is an example:

Get-History example
I wondered if it is possible to pipe the Get-History output and run it again. I could bet yes but I never tried before.
Yes, it is possible! 🙂
Example:

Pipe Get-History to Invoke-Expression
Conclusion:
If you don’t want to copy & paste the executed command from the Get-History output or neither try to find the command using keyboard up and down arrow keys, you can use:
Get-History -Id <number> | Invoke-Expression
Thank you for reading

2 Comments