โ† Files

Windows System Cleaner and Optimizer ๐Ÿงนโœจ#

Enterprise-grade Windows cleanup automation tool with enhanced safety features, system backup integration, and PowerShell 7+ optimization. Safely clears browser caches, temp files, system logs, and optimizes component store for maximum performance and disk space recovery.

Windows System Cleaner and Optimizer v5.2 is a comprehensive, professional-grade automation solution designed for system administrators, IT professionals, and power users who require reliable disk cleanup with enhanced safety measures. The latest version introduces advanced backup options, PowerShell 7+ optimizations, and enterprise-grade safety confirmations for dangerous operations.

๐Ÿš€ What's New in Version 5.2#

โœจ Enhanced Safety Features#

โšก PowerShell 7+ Optimizations#

๐Ÿ›ก๏ธ Enterprise Safety Enhancements#

๐Ÿ”ง Technical Improvements#

โšก Quick Start#

1. PowerShell Version (Recommended)#

# Clone and install
git clone https://github.com/paulmann/Windows-Cleaner-and-Optimizer.git
cd Windows-Cleaner-and-Optimizer

# Basic cleanup with safety features
.\Cleanup-Windows-Senior.ps1

# Enhanced safety with system restore point
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint

# Force mode for automated deployments
.\Cleanup-Windows-Senior.ps1 -Force

# Dry run with safety confirmations
.\Cleanup-Windows-Senior.ps1 -DryRun -EnableSafetyMode

# One-time bypass execution policy
powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -EnableSafetyMode

2. Batch Version (Alternative - Legacy Support)#

# Download and run (Administrator required)
curl -L -o Cleanup-Windows-Senior.bat "https://github.com/paulmann/Windows-Cleaner-and-Optimizer/raw/main/Cleanup-Windows-Senior.bat"
Cleanup-Windows-Senior.bat

# Or run from repository
git clone https://github.com/paulmann/Windows-Cleaner-and-Optimizer.git
cd Windows-Cleaner-and-Optimizer
Cleanup-Windows-Senior.bat

๐Ÿ“‹ Table of Contents#

  1. ๐Ÿš€ What's New in Version 5.2

  2. โšก Quick Start

  3. โœจ Key Features

  4. ๐Ÿ›ก๏ธ Safety and Backup Features

  5. โšก PowerShell 7+ Enhancements

  6. ๐Ÿ“‹ Installation & Usage

  7. ๐Ÿ—๏ธ Advanced Features

  8. ๐Ÿ”— DevOps Integration

  9. ๐Ÿข Enterprise Usage

  10. ๐Ÿ” Troubleshooting

  11. ๐Ÿค Contributing

  12. ๐Ÿ“„ License

  13. ๐Ÿ‘จโ€๐Ÿ’ป Author & Support

โœจ Key Features#

๐Ÿ›ก๏ธ Enterprise-Grade Safety (Enhanced)#

โšก PowerShell 7+ Optimization#

๐ŸŽฏ Comprehensive Cleanup Capabilities#

๐Ÿ“Š Advanced System Optimization#

๐Ÿ”„ Multi-Format Support#

๐Ÿ›ก๏ธ Safety and Backup Features#

Safety Mode Configuration#

Version 5.2 introduces comprehensive safety features to prevent accidental data loss or system instability:

# Enable safety mode (recommended for interactive use)
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode

# Disable safety mode (use with caution)
.\Cleanup-Windows-Senior.ps1 -NoSafetyMode

# Force mode bypasses all safety confirmations
.\Cleanup-Windows-Senior.ps1 -Force

System Restore Point Integration#

# Create restore point before cleanup
.\Cleanup-Windows-Senior.ps1 -CreateRestorePoint

# Skip restore point creation
.\Cleanup-Windows-Senior.ps1 -NoCreateRestorePoint

# Combined safety approach
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint

System Image Backup#

# Launch system image backup after cleanup
.\Cleanup-Windows-Senior.ps1 -CreateSystemImage

# Full safety configuration
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint -CreateSystemImage

Dangerous Operations with Risk Assessment#

The script categorizes operations by risk level and requires confirmation for high-risk tasks:

Risk Level Operations Confirmation Required
High Windows Update Full Cleanup, DISM Advanced Operations, Patch Cache Cleanup Always in Safety Mode
Medium Recycle Bin Cleanup, Event Logs Clearing Always in Safety Mode
Low Temp Files, Browser Caches, Prefetch Cleanup Never

โšก PowerShell 7+ Enhancements#

Automatic Feature Detection#

The script automatically detects PowerShell version and enables enhanced features:

# PowerShell 7+ features automatically enabled:
# - Parallel processing
# - Modern CIM commands
# - Enhanced telemetry
# - Improved color support
.\Cleanup-Windows-Senior.ps1

# Manual control of PS7+ features
.\Cleanup-Windows-Senior.ps1 -UseParallelProcessing -EnableTelemetry

Performance Optimizations#

# Parallel processing for faster execution (PS7+ only)
.\Cleanup-Windows-Senior.ps1 -UseParallelProcessing

# Enhanced telemetry and performance metrics
.\Cleanup-Windows-Senior.ps1 -EnableTelemetry

# Disable specific PS7+ features if needed
.\Cleanup-Windows-Senior.ps1 -NoUseParallelProcessing -NoEnableTelemetry

Backward Compatibility#

Full compatibility with PowerShell 5.1+ with graceful feature degradation:

# Works identically on PS5.1 and PS7+
# Enhanced features automatically disabled on older versions
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint

๐Ÿ“‹ Installation & Usage#

System Requirements#

Installation Options#

# Clone repository
git clone https://github.com/paulmann/Windows-Cleaner-and-Optimizer.git
cd Windows-Cleaner-and-Optimizer

# Choose your preferred version:
# PowerShell (Enhanced): .\Cleanup-Windows-Senior.ps1
# Batch (Legacy): .\Cleanup-Windows-Senior.bat

Option 2: Direct Download#

# PowerShell version (v5.2 with safety features)
$url = 'https://github.com/paulmann/Windows-Cleaner-and-Optimizer/raw/main/Cleanup-Windows-Senior.ps1'
Invoke-WebRequest -Uri $url -OutFile 'Cleanup-Windows-Senior.ps1'

# Batch version (legacy)
$url = 'https://github.com/paulmann/Windows-Cleaner-and-Optimizer/raw/main/Cleanup-Windows-Senior.bat'
Invoke-WebRequest -Uri $url -OutFile 'Cleanup-Windows-Senior.bat'

Option 3: Package Manager (Future)#

# Using PowerShell Gallery (planned)
# Install-Script -Name WindowsCleanerOptimizer

# Using Chocolatey (planned)
# choco install windows-cleaner-optimizer

PowerShell Setup#

Administrator Privileges#

This script MUST be run as Administrator. Right-click PowerShell and select Run as Administrator, or use:

# Start PowerShell as Administrator
powershell.exe -Command "Start-Process PowerShell -Verb RunAs"

# Verify administrator privileges
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

Execution Policy#

If you encounter "execution of scripts is disabled on this system":

# One-time bypass (recommended for testing)
powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -EnableSafetyMode

# Set for current user (permanent solution)
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

# Temporary session policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

# Check current policy
Get-ExecutionPolicy -List

Safety Configuration#

Interactive Safety Mode#

# Recommended for interactive use - confirms dangerous operations
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode

# With restore point creation for added safety
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint

Automated Deployment#

# Force mode for scripts and automated deployment
.\Cleanup-Windows-Senior.ps1 -Force

# Force mode with specific operations only
.\Cleanup-Windows-Senior.ps1 -Force -CleanTempFiles -CleanBrowserCaches

# Safety disabled for known environments
.\Cleanup-Windows-Senior.ps1 -NoSafetyMode

Backup Integration#

# Full safety with both restore point and system image
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint -CreateSystemImage

# Restore point only (most common)
.\Cleanup-Windows-Senior.ps1 -CreateRestorePoint

# System image only (takes longer)
.\Cleanup-Windows-Senior.ps1 -CreateSystemImage

Usage Examples#

Basic Safety-First Usage#

# Recommended for most users - maximum safety
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint

# Dry run to preview changes with safety
.\Cleanup-Windows-Senior.ps1 -DryRun -EnableSafetyMode

# Clean for all users with safety confirmations
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CleanForAllUsers

Advanced Safety Configuration#

# Custom safety configuration
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint -NoCreateSystemImage

# Specific operation control with safety
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CleanTempFiles -CleanBrowserCaches -NoCleanEventLogs

# PowerShell 7+ optimized with safety
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -UseParallelProcessing -EnableTelemetry

Enterprise Deployment#

# Force mode for automated scripts (use with caution)
.\Cleanup-Windows-Senior.ps1 -Force

# Limited operations in force mode
.\Cleanup-Windows-Senior.ps1 -Force -CleanTempFiles -CleanBrowserCaches -NoCleanRecycleBin

# Custom log path with safety
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -LogPath "C:\Logs\cleanup.log" -DaysOld 14

PowerShell 7+ Optimized#

# Leverage all PS7+ enhancements
.\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -UseParallelProcessing -EnableTelemetry

# Performance-focused with safety
.\Cleanup-Windows-Senior.ps1 -UseParallelProcessing -CreateRestorePoint

# Enhanced logging and telemetry
.\Cleanup-Windows-Senior.ps1 -EnableTelemetry -LogPath "C:\Logs\detailed-cleanup.log"

Batch Version (Legacy)#

REM Basic usage (limited safety features)
Cleanup-Windows-Senior.bat

REM The batch version provides basic cleanup:
REM - All cleanup operations with default settings
REM - Interactive progress display
REM - Basic error reporting
REM - Administrator privilege checking
REM - Limited safety features compared to PowerShell version

๐Ÿ—๏ธ Advanced Features#

Enhanced Browser Cache Management#

The script safely cleans browser caches for major browsers with user-specific handling:

# Browser-specific cleanup paths with safety
Chrome: %USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Cache
Edge: %USERPROFILE%\AppData\Local\Microsoft\Edge\User Data\Default\Cache
Firefox: %USERPROFILE%\AppData\Local\Mozilla\Firefox\Profiles\*\cache2
Opera: %USERPROFILE%\AppData\Roaming\Opera Software\Opera Stable\Cache
Yandex: %USERPROFILE%\AppData\Local\Yandex\YandexBrowser\User Data\Default\Cache

# Browser process management with safety stops
Stop-ProcessSafely -ProcessNames @("chrome", "msedge", "firefox", "opera", "yandex")

Advanced System File and Component Optimization#

Enhanced system optimization features with safety checks:

# System File Checker execution with error handling
sfc /scannow

# DISM component cleanup operations with safety confirmations
dism /online /cleanup-image /startcomponentcleanup
dism /online /cleanup-image /startcomponentcleanup /resetbase
dism /online /cleanup-image /spsuperseded

# Component store analysis with reporting
dism /online /cleanup-image /analyzecomponentstore

# Enhanced component cleanup via Task Scheduler
schtasks.exe /Run /TN \Microsoft\Windows\Servicing\StartComponentCleanup

Service Management with Safety#

Enhanced service handling during cleanup operations:

# Windows Update service management with error recovery
$wuService = Get-Service -Name wuauserv -ErrorAction SilentlyContinue
$wuServiceRunning = $false
if ($wuService -and $wuService.Status -eq 'Running') {
    $wuServiceRunning = $true
    Stop-Service -Name wuauserv -Force -ErrorAction SilentlyContinue
    # ... perform cleanup operations ...
    if ($wuServiceRunning) {
        Start-Service -Name wuauserv -ErrorAction SilentlyContinue
    }
}

Enhanced Logging System#

PowerShell v5.2 Enhanced Logging:

# Comprehensive logging with safety operations tracking
$logPath = "$env:TEMP\WindowsCleanup.log"

# Enhanced log levels with safety-specific logging
Write-LogMessage "Starting Windows cleanup process" -Level Info
Write-LogMessage "Safety Mode: Enabled" -Level Safety
Write-LogMessage "Administrator privileges confirmed" -Level Success
Write-LogMessage "[DRY RUN] Would clean browser caches" -Level DryRun
Write-LogMessage "Dangerous operation requires confirmation" -Level Safety
Write-LogMessage "Installation failed with exit code 2359302" -Level Error

# Safety-specific logging functions
Write-SafetyInfo "System Restore Point creation initiated"
Write-SafetyInfo "Dangerous operation confirmed by user"

Enhanced Telemetry (PS7+):

# Performance metrics and operation tracking
$Global:CleanupStatistics = @{
    OperationsCompleted = 0
    OperationsFailed = 0
    OperationsSkipped = 0
}

Update-Telemetry -Message "Operation completed" -Level "Success"
Update-Telemetry -Message "Operation failed" -Level "Error"

๐Ÿ”— DevOps Integration#

CI/CD Pipeline Integration with Safety#

GitHub Actions with Enhanced Safety#

name: Deploy Windows Cleanup v5.2
on:
  schedule:
    - cron: '0 2 * * 1'  # Weekly on Monday 2 AM
  workflow_dispatch:

jobs:
  deploy-cleanup:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v3
      
      - name: Deploy PowerShell Version with Safety
        run: |
          powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -Force -LogPath "C:\Logs\cleanup-${{ github.run_id }}.log"
        shell: cmd
        
      - name: Safety-Conscious Deployment
        run: |
          powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -EnableSafetyMode -CreateRestorePoint -UseParallelProcessing
        shell: cmd

Azure DevOps with Enhanced Features#

trigger:
  branches:
    include:
      - main

pool:
  name: 'Windows-Agents'

steps:
- powershell: |
    .\Cleanup-Windows-Senior.ps1 -EnableSafetyMode -CreateRestorePoint -UseParallelProcessing
  displayName: 'Run Windows Cleanup with Safety'
  continueOnError: true
  
- powershell: |
    .\Cleanup-Windows-Senior.ps1 -Force -CleanTempFiles -CleanBrowserCaches
  displayName: 'Fast Cleanup (Force Mode)'
  condition: always()

Group Policy Deployment with Safety#

Create a Group Policy Object (GPO) for mass deployment with safety considerations:

# PowerShell script deployment via GPO with safety
# Computer Configuration โ†’ Policies โ†’ Windows Settings โ†’ Scripts (Startup/Shutdown)
# Add: powershell.exe -ExecutionPolicy Bypass -File "\\domain\sysvol\scripts\Cleanup-Windows-Senior.ps1" -Force

# Safety-conscious deployment for user workstations
# Add: powershell.exe -ExecutionPolicy Bypass -File "\\domain\sysvol\scripts\Cleanup-Windows-Senior.ps1" -EnableSafetyMode -CreateRestorePoint

# Batch file deployment via GPO (simpler, fewer safety features)
# Computer Configuration โ†’ Policies โ†’ Windows Settings โ†’ Scripts (Startup/Shutdown) 
# Add: \\domain\sysvol\scripts\Cleanup-Windows-Senior.bat

SCCM Integration with Safety Options#

Application Deployment with Safety Configuration:

REM Detection Method
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild | find "26200"

REM Installation Command (PowerShell with Safety)
powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File ".\Cleanup-Windows-Senior.ps1" -Force

REM Installation Command (PowerShell with Enhanced Safety)
powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File ".\Cleanup-Windows-Senior.ps1" -EnableSafetyMode -CreateRestorePoint

REM Installation Command (Batch - Limited Safety Features)
Cleanup-Windows-Senior.bat

REM Return Codes
REM 0 = Success
REM 1 = General Failure
REM 2 = Access Denied
REM 3 = Service Error
REM 4 = Disk Space Error
REM 5 = Safety Confirmation Denied

๐Ÿข Enterprise Usage#

Mass Deployment with Safety Policies#

PowerShell DSC Configuration with Safety#

Configuration WindowsCleanupEnterprise {
    Import-DscResource -ModuleName PSDesiredStateConfiguration
    
    Node "localhost" {
        Script RunCleanupWithSafety {
            SetScript = {
                & "C:\Scripts\Cleanup-Windows-Senior.ps1" -EnableSafetyMode -CreateRestorePoint -UseParallelProcessing
            }
            TestScript = {
                # Check if cleanup is needed (always run for maintenance)
                return $false
            }
            GetScript = {
                return @{ Result = "Windows Cleanup Status" }
            }
        }
        
        Script RunCleanupForced {
            SetScript = {
                & "C:\Scripts\Cleanup-Windows-Senior.ps1" -Force -LogPath "C:\Logs\cleanup.log"
            }
            TestScript = {
                # Check last cleanup time
                $lastCleanup = Get-Content "C:\Logs\cleanup.log" -Tail 1 -ErrorAction SilentlyContinue
                return $lastCleanup -like "*COMPLETED SUCCESSFULLY*"
            }
            GetScript = {
                return @{ Result = "Forced Cleanup Status" }
            }
        }
    }
}

Intune Deployment (Win32 App) with Safety#

# Package the script for Intune deployment with safety options
# Create intunewin file with Microsoft Win32 Content Prep Tool

# Install command with safety
cmd /c "powershell.exe -ExecutionPolicy Bypass -File `"Cleanup-Windows-Senior.ps1`" -EnableSafetyMode -CreateRestorePoint"

# Install command for automated environments
cmd /c "powershell.exe -ExecutionPolicy Bypass -File `"Cleanup-Windows-Senior.ps1`" -Force"

# Detection rule
if (Test-Path "C:\ProgramData\WindowsCleanup\last-run.txt") {
    $lastRun = Get-Content "C:\ProgramData\WindowsCleanup\last-run.txt"
    $lastRunDate = [DateTime]::Parse($lastRun)
    if ((Get-Date) - $lastRunDate -lt [TimeSpan]::FromDays(7)) {
        Write-Output "Recently run"
        exit 0
    }
}
exit 1

# Return codes with safety considerations
# 0 = Success
# 1 = General Failure
# 2 = Safety Confirmation Denied
# 3 = Administrator Privileges Required
# Other = Specific Operation Failure

Automated Workflows with Safety#

Task Scheduler Integration with Safety Configuration#

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2">
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2025-10-15T02:00:00</StartBoundary>
      <ScheduleByWeek>
        <WeeksInterval>1</WeeksInterval>
        <DaysOfWeek>
          <Monday />
        </DaysOfWeek>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Actions>
    <!-- Safety-conscious execution -->
    <Exec>
      <Command>C:\Scripts\Cleanup-Windows-Senior.ps1</Command>
      <Arguments>-EnableSafetyMode -CreateRestorePoint -LogPath "C:\Logs\scheduled-cleanup.log"</Arguments>
    </Exec>
    <!-- Force mode for automated environments -->
    <Exec>
      <Command>C:\Scripts\Cleanup-Windows-Senior.ps1</Command>
      <Arguments>-Force -LogPath "C:\Logs\automated-cleanup.log"</Arguments>
    </Exec>
  </Actions>
  <Principals>
    <Principal>
      <UserId>S-1-5-18</UserId>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
</Task>

Monitoring and Reporting with Safety Tracking#

Event Log Integration with Safety Events#

# PowerShell version writes safety events to Application log
Write-EventLog -LogName Application -Source "WindowsCleanup" -EventId 1000 -Message "Cleanup started with Safety Mode"
Write-EventLog -LogName Application -Source "WindowsCleanup" -EventId 1001 -Message "System Restore Point created"
Write-EventLog -LogName Application -Source "WindowsCleanup" -EventId 1002 -Message "Dangerous operation confirmed"
Write-EventLog -LogName Application -Source "WindowsCleanup" -EventId 2000 -Message "Cleanup completed successfully"
Write-EventLog -LogName Application -Source "WindowsCleanup" -EventId 3000 -Message "Safety confirmation denied - operation skipped"

# Check cleanup status across domain with safety compliance
Get-ADComputer -Filter * | ForEach-Object {
    $lastCleanup = Invoke-Command -ComputerName $_.Name -ScriptBlock {
        Get-EventLog -LogName Application -Source "WindowsCleanup" -Newest 1 -ErrorAction SilentlyContinue
    } -ErrorAction SilentlyContinue
    
    $safetyCompliant = $lastCleanup.Message -like "*Safety Mode*" -or $lastCleanup.Message -like "*Restore Point*"
    
    [PSCustomObject]@{
        ComputerName = $_.Name
        LastCleanup = $lastCleanup.TimeGenerated
        Status = if ($lastCleanup) { "Recent" } else { "Needs Cleanup" }
        SafetyCompliant = $safetyCompliant
    }
} | Export-Csv "WindowsCleanup_Compliance_Report.csv"

๐Ÿ” Troubleshooting#

Common Issues and Solutions#

Permission and Safety Errors#

# Problem: "Access denied" or safety confirmation denied
# Solution: Ensure administrator privileges and safety compliance

# Check current privileges with safety context
if (-not (Test-AdminPrivileges)) {
    Write-ErrorInfo "Administrator privileges required for safety operations"
    exit 2
}

# Safety confirmation handling
if (-not (Confirm-DangerousOperation -OperationName "CleanRecycleBin" -Description "Permanent deletion" -RiskLevel "Medium")) {
    Write-SkippedInfo "Operation skipped due to safety confirmation denial"
    exit 5
}

ExecutionPolicy Issues (PowerShell Only)#

# Problem: "cannot be loaded because running scripts is disabled"
# Solution: Use one-time bypass or adjust policy with safety considerations

# Quick fix - one-time bypass with safety
powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -EnableSafetyMode

# Permanent fix for current user
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

# Check current policy
Get-ExecutionPolicy -List

# Safety note: Execution policy is a security feature, bypass only from trusted sources

Service Access Issues with Safety#

# Problem: Cannot stop Windows Update service during safety operations
# Solution: Check service dependencies and wait for operations to complete

# Enhanced service status check with safety
$services = @("wuauserv", "BITS", "CryptSvc")
foreach ($service in $services) {
    $svc = Get-Service -Name $service -ErrorAction SilentlyContinue
    if ($svc) {
        Write-SafetyInfo "Service $service status: $($svc.Status), StartType: $($svc.StartType)"
    }
}

# Check for running Windows Update operations with safety timeout
$timeout = New-TimeSpan -Minutes 5
$stopTime = (Get-Date).Add($timeout)
while ((Get-Date) -lt $stopTime) {
    $updateProcesses = Get-Process | Where-Object { 
        $_.ProcessName -like "*update*" -or $_.ProcessName -like "*dism*" 
    }
    if (-not $updateProcesses) { break }
    Start-Sleep -Seconds 10
}

# Safety fallback: Skip operation if services cannot be managed safely
if ((Get-Date) -ge $stopTime) {
    Write-SkippedInfo "Service operations timeout - skipping for safety"
}

Disk Space Issues with Safety#

# Problem: Not enough space for cleanup operations or restore points
# Enhanced space check with safety thresholds

$safetyThresholdGB = 2  # Minimum free space for safety operations
$drives = Get-CimInstance -Class Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 }

foreach ($drive in $drives) {
    $freeSpaceGB = [math]::Round($drive.FreeSpace / 1GB, 2)
    $driveLetter = $drive.DeviceID
    
    Write-LogMessage "Drive $driveLetter has $freeSpaceGB GB free space" -Level Info
    
    if ($freeSpaceGB -lt $safetyThresholdGB) {
        Write-SafetyInfo "Low disk space on $driveLetter - $freeSpaceGB GB free (minimum: $safetyThresholdGB GB)"
        
        if ($driveLetter -eq $env:SystemDrive -and $CleanupConfig.CreateRestorePointEnabled) {
            Write-SkippedInfo "Insufficient space for System Restore Point - skipping creation"
            $CleanupConfig.CreateRestorePointEnabled = $false
        }
    }
}

# Solution: Ensure adequate free space before safety operations

Enhanced Error Codes#

Exit Code PowerShell Batch Description Safety Impact Solution
0 โœ… Success โœ… Success Cleanup completed successfully Safety operations completed No action needed
1 โŒ General failure โŒ General failure Various errors Safety may be compromised Check detailed logs
2 โŒ Access denied โŒ Access denied Insufficient privileges Safety operations blocked Run as Administrator
3 โŒ Service error โŒ Service error Cannot manage services Safety stop/start failed Check Windows services
4 โŒ Disk space error โŒ Disk space error Insufficient disk space Restore points may fail Free up space
5 โŒ Safety denied โš ๏ธ Limited Safety confirmation denied Operation skipped by user Review safety settings
6 โŒ Backup failed โš ๏ธ Limited System backup failed Proceed with caution Check backup settings

Diagnostic Commands with Safety Context#

# Enhanced System Information with safety context
systeminfo | find "OS Version"
Get-ComputerInfo | Select WindowsVersion, WindowsEditionId, WindowsInstallationType
Get-CimInstance -ClassName Win32_ComputerSystem | Select Model, Manufacturer, TotalPhysicalMemory

# Disk Space Check with safety thresholds
Get-CimInstance -Class Win32_LogicalDisk | Select DeviceID, 
    @{Name="Size(GB)";Expression={[math]::Round($_.Size/1GB,2)}}, 
    @{Name="FreeSpace(GB)";Expression={[math]::Round($_.FreeSpace/1GB,2)}},
    @{Name="SafetyStatus";Expression={if ([math]::Round($_.FreeSpace/1GB,2) -gt 2){"Adequate"}else{"Low"}}}

# Service Status with safety dependencies
Get-Service -Name wuauserv, BITS, CryptSvc, VSS | Select Name, Status, StartType, RequiredServices

# Safety Configuration Check
Write-Host "Safety Mode: $(if ($CleanupConfig.SafetyModeEnabled) {'ENABLED'} else {'DISABLED'})"
Write-Host "Restore Point: $(if ($CleanupConfig.CreateRestorePointEnabled) {'ENABLED'} else {'DISABLED'})"
Write-Host "System Image: $(if ($CleanupConfig.CreateSystemImageEnabled) {'ENABLED'} else {'DISABLED'})"
Write-Host "Force Mode: $(if ($Force -or $ForceShort) {'ENABLED'} else {'DISABLED'})"

# PowerShell Version and Capabilities
Write-Host "PowerShell Version: $($PSVersionTable.PSVersion)"
Write-Host "Platform: $($PSVersionTable.Platform)"
Write-Host "PowerShell 7+ Features: $(if ($Script:IsPS7Plus) {'AVAILABLE'} else {'NOT AVAILABLE'})"
Write-Host "Parallel Processing: $(if ($CleanupConfig.UseParallelProcessing) {'ENABLED'} else {'DISABLED'})"

๐Ÿค Contributing#

We welcome contributions! Here's how to get involved with the enhanced v5.2 codebase:

Development Setup with Safety Testing#

# Fork and clone the repository
git clone https://github.com/yourusername/Windows-Cleaner-and-Optimizer.git
cd Windows-Cleaner-and-Optimizer

# Test safety features thoroughly
# Safety mode testing
powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -EnableSafetyMode -DryRun

# Force mode testing
powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -Force -DryRun

# Backup feature testing
powershell.exe -ExecutionPolicy Bypass -File ".\Cleanup-Windows-Senior.ps1" -CreateRestorePoint -DryRun

# Batch version testing in legacy environments
.\Cleanup-Windows-Senior.bat

Contribution Guidelines for Safety Features#

  1. Fork the repository

  2. Create a feature branch (git checkout -b feature/enhanced-safety)

  3. Test thoroughly on multiple Windows systems with different safety scenarios

  4. Update documentation for new safety parameters and features

  5. Commit changes (git commit -m 'Add enhanced safety confirmation system')

  6. Push to branch (git push origin feature/enhanced-safety)

  7. Open a Pull Request with safety impact assessment

Enhanced Code Standards#

Priority Areas for Contribution#

๐Ÿ“„ License#

This project is licensed under the PolyForm Noncommercial License 1.0.0 - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author & Support#

Mikhail Deynekin

Enhanced Support Channels#


โญ Star this repository if it helped you!#

Windows System Cleaner and Optimizer v5.2 - Making Windows cleanup fast, reliable, safe, and enterprise-ready ๐Ÿงนโœจ๐Ÿ›ก๏ธ

Report Bug ยท
Request Feature ยท
Safety Guidelines ยท
Documentation


๐Ÿ”’ Safety Disclaimer#

Important: Always test cleanup operations in a non-production environment first. Use safety features (-EnableSafetyMode, -CreateRestorePoint) when performing cleanup on important systems. The authors are not responsible for data loss or system instability resulting from improper use of this tool. Ensure you have adequate backups before performing system cleanup operations.