added new removal for outlook backup files

This commit is contained in:
2022-11-22 13:20:18 -05:00
parent 64d6b36bd0
commit e900b65cc5
+12 -2
View File
@@ -1,4 +1,4 @@
. "C:\Users\dyoder\Documents\Emberkom\Data\Projects\development\management-scripts\Tools.ps1"
# When deleting temp files en masse, only delete files/folders older than the number of days specified here
$OlderThan = 7
$TimeDelta = New-TimeSpan -Days $OlderThan
@@ -184,7 +184,6 @@ ForEach ( $userProfile in $(EnumUserProfiles) ) {
}
}
# Remove duplicate downloads
# Separate the possible duplicates from the rest
$PossibleDuplicates = @()
@@ -220,6 +219,17 @@ ForEach ( $userProfile in $(EnumUserProfiles) ) {
}
}
# Remove old Outlook backup files
$OldOutlookBackupFiles = Get-ChildItem -Path "${userProfile}\AppData\Local\Microsoft\Outlook\*" -File -Filter '*.bak' -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -lt ((Get-Date) - $TimeDelta) }
If ( $OldOutlookBackupFiles ) {
LogMsg "Found Outlook backup files older than ${OlderThan} days:"
ForEach ( $file in $OldOutlookBackupFiles ) {
$path = $file.FullName
LogMsg "Deleting: ""${path}"""
Try { Remove-Item -Path $path -Force -ErrorAction SilentlyContinue }
Catch { LogErr $_.Exception.Message }
}
}
}
# Silently run cleanmgr.exe with default settings