Last active
November 8, 2017 18:50
-
-
Save steviecoaster/9953cefed1ddec8e3ac792d1f52df13c to your computer and use it in GitHub Desktop.
Automatically create a transcript of your Powershell Session. Keeps 7 days worth of history by default
This file contains 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
<# | |
.SYNOPSIS | |
Automatically create transcript of your Powershell session. | |
.DESCRIPTION | |
Add this function to your Powershell Profile and call it with Invoke-SessionLog -Logpath \some\path to automatically keep | |
session history each time you open up powershell. | |
.EXAMPLE | |
Invoke-SessionLog -LogPath C:\PSLogs -DaysToKeep 7 | |
#> | |
Function Invoke-SessionLog { | |
Param( | |
[cmdletBinding()] | |
[Parameter(Mandatory, Position = 0)] | |
[String]$LogPath, | |
[Parameter(Mandatory,Position = 1)] | |
[String]$DaysToKeep | |
) | |
$Oldlogs = Get-ChildItem -Path $LogPath -Recurse -Force | |
foreach ($log in $Oldlogs) { | |
If ($log.CreationTime -lt (Get-Date).AddDays(-$DaysToKeep)) { | |
Remove-Item $log -Force | |
} | |
} | |
Start-Transcript -OutputDirectory $LogPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment