One of the wonderful things about the bash shell on *nix systems is that history persists between sessions so you can easily reuse commands. Unfortunately, this is not built into powershell on windows, but you can get close to it by putting this into your profile.ps1 which is read each time you start up powershell.
# Persistent History
# Save last 200 history items on exit$MaximumHistoryCount = 200$historyPath = Join-Path (split-path $profile) history.clixml# Hook powershell's exiting event & hide the registration with -supportevent (from nivot.org)Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action {Get-History -Count $MaximumHistoryCount | Export-Clixml (Join-Path (split-path $profile) history.clixml) }# Load previous history, if it existsif ((Test-Path $historyPath)) {Import-Clixml $historyPath | ? {$count++;$true} | Add-HistoryWrite-Host -Fore Green "`nLoaded $count history item(s).`n"}# Aliases and functions to make it usefulNew-Alias -Name i -Value Invoke-History -Description "Invoke history alias"Rename-Item Alias:h original_h -Forcefunction h { Get-History -c $MaximumHistoryCount }function hg($arg) { Get-History -c $MaximumHistoryCount | out-string -stream | select-string $arg }
This code does several things. First is expands the history buffer from 64 to 200 lines. You can make it bigger by changing the $MaximumHistoryCount. Second it sets up exit event that saves the history out to a file whenever you exit powershell and then reads in the history when you start powershell. For some reason, even though the history looks ok, the arrow buttons will not work so I set up some aliases and functions to use the history. 'h' will list the the history and 'hg <string>' will search the history for <string>. Finally 'i ##' will then execute the item # from the history. It works well for me and I hope it will help you out also.