delete CBS.log if the archive space is >200MB

This commit is contained in:
2022-11-03 09:24:17 -04:00
parent afbc2e9b70
commit 5a9c6e1dec
+10
View File
@@ -28,6 +28,16 @@ If ( IsAdmin )
$CBSLogs = Get-ChildItem -Path "${Env:SystemRoot}\Logs\CBS\*" -File -Include "CbsPersist_*.log", "CbsPersist_*.cab"
If ( $CBSLogs )
{
$TotalBytes = 0
ForEach ( $CBSLog in $CBSLogs) { $TotalBytes += $CBSLog.Length }
$TotalSize = $TotalBytes / 1MB
If ( $TotalSize -ge 200 ) {
LogMsg "Total CBS log archive size: ${TotalSize}MB"
Control-Service -Stop 'TrustedInstaller'
LogMsg "Deleting primary CBS.log file"
Remove-Item "${Env:SystemRoot}\Logs\CBS\CBS.log" -Force -ErrorAction SilentlyContinue }
Control-Service -Start 'TrustedInstaller'
}
LogMsg "Deleting archived CBS logs from ${Env:SystemRoot}\Logs\CBS"
ForEach ( $CBSLog in $CBSLogs ) { Remove-Item $CBSLog -Force -ErrorAction SilentlyContinue }