-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearTranscripts.ps1
More file actions
27 lines (23 loc) · 1.03 KB
/
ClearTranscripts.ps1
File metadata and controls
27 lines (23 loc) · 1.03 KB
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
if ($IsWindows) {
Import-Module -Name Recycle
}
elseif ($IsLinux) {
Set-Alias -Name 'Remove-ItemSafely' -Value 'trash' -Option Private -Scope Private
}
elseif ($IsMacOS) {
Set-Alias -Name 'Remove-ItemSafely' -Value 'trash' -Option Private -Scope Private
}
$PowerShellTranscriptsPath = Join-Path -Path $HOME -ChildPath "PowerShellTranscripts"
$TranscriptFilePaths = Get-ChildItem $PowerShellTranscriptsPath -File
$TranscriptAgeThreshold = New-TimeSpan -Hours (7 * 24)
foreach ($TranscriptFilePath in $TranscriptFilePaths) {
$parts = $TranscriptFilePath.BaseName -split '--'
$dateParts = $parts[0] -split '-'
$timeParts = $parts[1] -split '-'
$TranscriptDate = Get-Date -Year $dateParts[0] -Month $dateParts[1] -Day $dateParts[2] -Hour $timeParts[0] -Minute $timeParts[1] -Second $timeParts[2]
$TranscriptAge = New-TimeSpan -Start $TranscriptDate -End (Get-Date)
if ($TranscriptAge -gt $TranscriptAgeThreshold) {
Write-Host "Removing $TranscriptFilePath"
Remove-ItemSafely $TranscriptFilePath
}
}