-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.ps1
26 lines (21 loc) · 1.17 KB
/
profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Powershell profile to give persistent command history and logging. Orginal concept from:
# http://hackerhurricane.blogspot.com/2014/11/i-powershell-logging-what-everyone.html
# https://lopsa.org/content/persistent-history-powershell
# Place in: \\Windows\System32\WindowsPowerShell\v1.0\
$LogCommandHealthEvent = $true
$LogCommandLifecycleEvent = $true
# Save last 200 history items on exit
$MaximumHistoryCount = 200
$historyPath = Join-Path (split-path $profile) history.clixml
Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action {
Get-History -Count $MaximumHistoryCount | Export-Clixml (Join-Path (split-path $profile) history.clixml) }
# Load previous history
if ((Test-Path $historyPath)) {
Import-Clixml $historyPath | ? {$count++;$true} | Add-History
Write-Host -Fore Green "`nLoaded $count history item(s).`n"
}
# Aliases and functions to make it useful: Get-History / history
New-Alias -Name i -Value Invoke-History -Description "Invoke history alias"
Rename-Item Alias:\h original_h -Force
function h { Get-History -c $MaximumHistoryCount }
function hg($arg) { Get-History -c $MaximumHistoryCount | out-string -stream | select-string $arg }