From 0065e371e134fbe8a857363a16f9c3f43070ce18 Mon Sep 17 00:00:00 2001 From: dyoder Date: Tue, 8 Sep 2020 22:23:52 -0400 Subject: [PATCH] added several more logs to delete --- Cleanup-SystemTempFiles.ps1 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Cleanup-SystemTempFiles.ps1 b/Cleanup-SystemTempFiles.ps1 index 90682f4..7e2381f 100644 --- a/Cleanup-SystemTempFiles.ps1 +++ b/Cleanup-SystemTempFiles.ps1 @@ -4,18 +4,23 @@ If ( (IsWindowsVersion -ge "6.2") ) { Write-Output "Deleting old AppX log files from ${SysTemp}" - Get-ChildItem -Path $SysTemp | Where { $_.Name -like "AppXDeploymentServer_*.evtx" } | Remove-Item -Force - Get-ChildItem -Path $SysTemp | Where { $_.Name -like "AppxErrorReport_*.txt" } | Remove-Item -Force - Get-ChildItem -Path $SysTemp | Where { $_.Name -like "AppXPackaging_*.evtx" } | Remove-Item -Force - Get-ChildItem -Path $SysTemp | Where { $_.Name -like "Application_*.evtx" } | Remove-Item -Force + Get-ChildItem -Path $SysTemp | Where { $_.Name -like "AppXDeploymentServer_*.evtx" } | Remove-Item -Force -ErrorAction SilentlyContinue + Get-ChildItem -Path $SysTemp | Where { $_.Name -like "AppxErrorReport_*.txt" } | Remove-Item -Force -ErrorAction SilentlyContinue + Get-ChildItem -Path $SysTemp | Where { $_.Name -like "AppXPackaging_*.evtx" } | Remove-Item -Force -ErrorAction SilentlyContinue + Get-ChildItem -Path $SysTemp | Where { $_.Name -like "Application_*.evtx" } | Remove-Item -Force -ErrorAction SilentlyContinue + Get-ChildItem -Path $SysTemp | Where { $_.Name -like "System_*.evtx" } | Remove-Item -Force -ErrorAction SilentlyContinue } +## Remove computer log files +Get-ChildItem -Path $SysTemp | Where { $_.Name -like "Microsoft-Windows-AppReadiness_Admin_*.evtx" } | Remove-Item -Force -ErrorAction SilentlyContinue +Get-ChildItem -Path $SysTemp | Where { $_.Name -like "${Env:COMPUTERNAME}-*.log" } | Remove-Item -Force -ErrorAction SilentlyContinue + ## Remove runaway CBS logs $CBSLogDir = "${Env:SystemRoot}\Logs\CBS" If ( Test-Path $CBSLogDir ) { Write-Output "Deleting old CBS log files from ${CBSLogDir}" - Get-ChildItem -Path $CBSLogDir -File | Where { ( $_.Name -like "CbsPersist_*.log" ) -or ( $_.Name -like "CbsPersist_*.cab" ) } | Remove-Item -Force + Get-ChildItem -Path $CBSLogDir -File | Where { ( $_.Name -like "CbsPersist_*.log" ) -or ( $_.Name -like "CbsPersist_*.cab" ) } | Remove-Item -Force -ErrorAction SilentlyContinue } ## Remove all system temp files older than the specified number of days @@ -25,6 +30,6 @@ Write-Output "Deleting all files more than ${OlderThan} day(s) old ${SysTemp}" Foreach ( $item in (Get-ChildItem -Path "${SysTemp}") ) { ## If it's older than the number of days specified, recursively delete the directory - If ( $item.LastWriteTime -lt ((Get-Date) - $timedelta) ) { Remove-Item $item.FullName -Recurse -ErrorAction SilentlyContinue -Force } + If ( $item.LastWriteTime -lt ((Get-Date) - $timedelta) ) { Remove-Item $item.FullName -Recurse -ErrorAction SilentlyContinue -Force -ErrorAction SilentlyContinue } }