24 lines
1.3 KiB
PowerShell
24 lines
1.3 KiB
PowerShell
## Remove runaway AppX logs;n
|
|
If ( (IsWindowsVersion -ge "6.2") )
|
|
{
|
|
Write-Output "Deleting old AppX log files from ${Env:SystemRoot}\TEMP"
|
|
Get-ChildItem -Path "${Env:SystemRoot}\TEMP" | Where { $_.Name -like "AppXDeploymentServer_*.evtx" } | Remove-Item -Force
|
|
Get-ChildItem -Path "${Env:SystemRoot}\TEMP" | Where { $_.Name -like "AppxErrorReport_*.txt" } | Remove-Item -Force
|
|
Get-ChildItem -Path "${Env:SystemRoot}\TEMP" | Where { $_.Name -like "AppXPackaging_*.evtx" } | Remove-Item -Force
|
|
}
|
|
|
|
## Remove runaway CBS logs
|
|
Write-Output "Deleting old CBS log files from ${Env:SystemRoot}\Logs\CBS"
|
|
Get-ChildItem -Path "${Env:SystemRoom}\Logs\CBS" -File | Where { ( $_.Name -like "CbsPersist_*.log" ) -or ( $_.Name -like "CbsPersist_*.cab" ) } | Remove-Item -Force
|
|
|
|
## Remove all system temp files older than the specified number of days
|
|
$OlderThan=7
|
|
$timedelta = New-TimeSpan -Days $OlderThan
|
|
Write-Output "Deleting all files older than ${OlderThan} day(s) from ${Env:SystemRoom}\TEMP"
|
|
Foreach ( $item in (Get-ChildItem -Path "${Env:SystemRoot}\TEMP") )
|
|
{
|
|
## 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 }
|
|
|
|
}
|