Created
October 23, 2012 11:47
-
-
Save hoest/3938346 to your computer and use it in GitHub Desktop.
Keep Powershell history
This file contains hidden or 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
# profile folder | |
$profileFolder = split-path $profile | |
# save last 100 history items on exit; with the 'exit' command | |
$historyPath = Join-Path $profileFolder "ps_history.xml" | |
# hook powershell's exiting event and hide the registration with -supportevent. | |
Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action { | |
Get-History -Count 100 | Export-Clixml (Join-Path $profileFolder "ps_history.xml") } | |
# load previous history, if it exists | |
if((Test-Path $historyPath)) { | |
Import-Clixml $historyPath | ? { $count++; $true } | Add-History | |
Write-Host -Fore Green "Loaded $count history item(s).`n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment