SHARE
TWEET

Approximation of .bash_history in PowerShell

Lars-UT Feb 10th, 2012 222 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Add this to your profile to persist your command line history in PowerShell
  2. # Type 'bye' instead of 'exit' to quit a session, and 'checkpoint' when you want to force a save
  3. #  without exiting the current session
  4. #
  5.  
  6. ########################################################
  7. # History
  8. $MaximumHistoryCount = 31KB
  9.  
  10. if (!(Test-Path ~\PowerShell -PathType Container))
  11. {   New-Item ~\PowerShell -ItemType Directory
  12. }
  13.  
  14. function bye
  15. {   Get-History -Count $MaximumHistoryCount |Export-CSV ~\PowerShell\history.csv
  16.     exit
  17. }
  18.  
  19. function checkpoint
  20. {
  21. Get-History -Count $MaximumHistoryCount |Export-CSV ~\PowerShell\history.csv
  22. }
  23.  
  24. if (Test-path ~\PowerShell\History.csv)
  25. {   Import-CSV ~\PowerShell\History.csv |Add-History
  26. }
  27. ########################################################
RAW Paste Data
Top