-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
PS-History.ps1
31 lines (26 loc) · 1.62 KB
/
PS-History.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
27
28
29
30
31
# Get read PowerShell History file(s) from the current user's profile
$logpath = "$($env:APPDATA)\Microsoft\Windows\PowerShell\PSReadline\"
$logfiles = get-childitem -path $logpath -filter "*history*.txt" -Force -ErrorAction SilentlyContinue
$logentries = if($logfiles.count -ge 1){
foreach($log in $logfiles){
Write-Output ""
Write-Output "--------------------------------------------"
Write-Output "$($log) - Creation Time: $($log.CreationTime)"
Write-Output "$($log) - Creation Time: $($log.LastWriteTime)"
Write-Output "$($log) - Creation Time: $($log.LastAccessTime)"
Write-Output "--------------------------------------------"
Write-Output "Entries from $($log)"
Write-Output "--------------------------------------------"
Write-Output ""
$read = New-Object System.IO.StreamReader($log.FullName)
[int]$i = 1
while(!$read.EndOfStream ) {
$line = $read.ReadLine()
Write-Output "($($i)) $($line)"
$i++
}
$read.Close()
$read.Dispose()
}
}
$logentries