When you type “h” in PowerShell, you see the PowerShell History of commands in your session.
Also, pressing F7 Key in PowerShell console brings up a command history dialog box where you can choose and run history items like in the following image
But this feature doesn’t work in Powershell ISE or any other script editor.
Well to the rescue following is a quick function which uses Out-GridView cmdlet to mimic the similar behavior like in the above image.
Better PowerShell History Function :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Hplus { | |
h|ogv -Title "Select the command(s) & hit 'OK' to run" -PassThru|%{iex $_.commandline} | |
} |
Not only this function allows you to just run the history items, but you can also select and run multiple of history items at once as in the following image.
When you hit OK, you’ll see all history items executed and echoed in your PowerShell console
Add this function to your Powershell profile and always keep it handy, to add it to your profile using the below oneliner –
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Content $profile -Value (iwr https://goo.gl/zpze7G) |
Hope you’ll find it useful, cheers!
Prateek Singh
Related posts
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,870 People Reached