making better use of powershell history
The native powershell Get-History
cmdlet returns results from the open console only and this history is lost when you close that console. But similarly to .bash_history
in Linux, the command line property from the Get-History
output are also written to a file called Console_history.txt
, which is useful as a more persistent history.
function hist
I added this to my powershell profile to make using Console_history.txt
more fun:
the hist
function gives me quick access to the contents of my Console_history.txt
function save-cmd
Often I want to save the command I have just run for later use, but I don’t want to leave the console and break my concentration. I added save-cmd
function my $Profile to pull the last item in my history, and save it to a file in my personal powershell repo. I can retrieve the content of this file with the shist
function.
The command below will add the last item in your history to your $Profile
go deeper
What will I find if I search the PSGallery for items related to “history”?
written by Mr. Monad Manifesto!
pretty neat alias in that script: ISH
lessons learned..
I should have searched PSGallery earlier. I plan to modify this script so that instead of pulling from Get-History, it pulls from a csv which will contain my Save-Cmd
output. I’ll have to also modify my Save-Cmd
function so that it stores the object output of get-history
instead of just the command line. Then i can make use of the gui and invoke-command
feature in jsnover’s script to work as a cool launcher for saved one-liners.
Leave a Comment