Team Carm Cyril - Powershell Toolkit

Windows 11 Performance Optimizer
Write-Host "Starting Windows 11 performance optimization..." -ForegroundColor Cyan

# --- Step 1: Clean temporary and cache files ---
Write-Host "`nCleaning temporary files..." -ForegroundColor Yellow
$paths = @(
    "$env:TEMP\*",
    "$env:WINDIR\Temp\*",
    "$env:LOCALAPPDATA\Microsoft\Windows\WebCache\*",
    "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache\*",
    "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*",
    "$env:LOCALAPPDATA\Mozilla\Firefox\Profiles\*\cache2\entries\*"
)
foreach ($p in $paths) {
    if (Test-Path $p) {
        Remove-Item $p -Recurse -Force -ErrorAction SilentlyContinue
    }
}
Write-Host "Temporary and cache files cleaned."

# --- Step 2: Disable unnecessary startup apps ---
Write-Host "`nDisabling startup apps..." -ForegroundColor Yellow
try {
    Get-CimInstance Win32_StartupCommand | ForEach-Object {
        Write-Host "Disabling startup entry: $($_.Name)"
        Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name $_.Name -ErrorAction SilentlyContinue
    }
} catch {
    Write-Host "Could not modify startup items. Try running PowerShell as Administrator." -ForegroundColor DarkYellow
}
Write-Host "Startup apps disabled (non-critical)."

# --- Step 3: Apply "Adjust for Best Performance" visual settings ---
Write-Host "`nApplying 'Adjust for Best Performance' settings..." -ForegroundColor Yellow

$visualEffectsKeys = @(
    "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects",
    "HKCU:\Software\Microsoft\Windows\DWM",
    "HKCU:\Control Panel\Desktop",
    "HKCU:\Control Panel\Desktop\WindowMetrics",
    "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
)

foreach ($key in $visualEffectsKeys) {
    if (!(Test-Path $key)) { New-Item -Path $key -Force | Out-Null }
}

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Name VisualFXSetting -Value 2 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\DWM" -Name EnableAeroPeek -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\DWM" -Name UseOLEDTaskbarTransparency -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name UserPreferencesMask -Value ([byte[]](0x90,0x12,0x03,0x80,0x10,0x00,0x00,0x00)) -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\WindowMetrics" -Name MinAnimate -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name TaskbarAnimations -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name ListviewAlphaSelect -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name ListviewShadow -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name IconsOnly -Value 1 -ErrorAction SilentlyContinue

Write-Host " 'Adjust for Best Performance' settings applied."

# --- Step 4: Disable background apps ---
Write-Host "`nDisabling background apps..." -ForegroundColor Yellow
$regPath2 = "HKCU:\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications"
if (!(Test-Path $regPath2)) { New-Item -Path $regPath2 -Force | Out-Null }
Set-ItemProperty -Path $regPath2 -Name "GlobalUserDisabled" -Value 1
Write-Host "Background apps disabled."

# --- Step 5: Run built-in Windows cleanup tool silently ---
Write-Host "`nRunning Storage Sense / Disk Cleanup..." -ForegroundColor Yellow
try {
    Start-Process cleanmgr.exe -ArgumentList "/sagerun:1" -NoNewWindow -ErrorAction SilentlyContinue
    Write-Host "Disk Cleanup initiated (if configured with /sageset:1)."
} catch {
    Write-Host "Unable to run Disk Cleanup. Configure using 'cleanmgr /sageset:1' first." -ForegroundColor DarkYellow
}

# --- Step 6: Optimize drives (defrag for HDD / trim for SSD) ---
Write-Host "`nOptimizing drives..." -ForegroundColor Yellow

Get-Volume |
    Where-Object { $_.DriveType -eq 'Fixed' -and $_.DriveLetter } |
    ForEach-Object {
        Write-Host "Optimizing drive $($_.DriveLetter)..."
        try {
            Optimize-Volume -DriveLetter $_.DriveLetter -Verbose -ErrorAction Stop
        } catch {
            Write-Host " Could not optimize drive $($_.DriveLetter): $($_.Exception.Message)" -ForegroundColor DarkYellow
        }
    }

Write-Host "Drives optimized."

# --- Step 7: Clear Windows update cache (safe cleanup) ---
Write-Host "`nClearing Windows Update cache..." -ForegroundColor Yellow
try {
    net stop wuauserv | Out-Null
    Remove-Item "C:\Windows\SoftwareDistribution\Download\*" -Recurse -Force -ErrorAction SilentlyContinue
    net start wuauserv | Out-Null
    Write-Host "Windows Update cache cleared."
} catch {
    Write-Host "Could not clear update cache (requires admin)." -ForegroundColor DarkYellow
}

# --- Step 8: Flush DNS cache ---
Write-Host "`nFlushing DNS cache..." -ForegroundColor Yellow
try {
    ipconfig /flushdns | Out-Null
    Write-Host "DNS cache flushed."
} catch {
    Write-Host "Unable to flush DNS cache." -ForegroundColor DarkYellow
}

# --- Step 9: Memory optimization (optional) ---
Write-Host "`nClearing standby memory (RAM)..." -ForegroundColor Yellow
$emptyStandbyTool = "EmptyStandbyList.exe"
if (Test-Path $emptyStandbyTool) {
    Start-Process -FilePath "cmd.exe" -ArgumentList "/c $emptyStandbyTool workingsets" -ErrorAction SilentlyContinue
    Write-Host "Memory optimized."
} else {
    Write-Host "Skipped — EmptyStandbyList.exe not found (optional tool)." -ForegroundColor DarkYellow
}

# --- Step 10: Completion message ---
Write-Host "`nAll optimizations completed successfully!" -ForegroundColor Green
Write-Host "Please restart your computer for all changes to take full effect."
Clear DNS, Temp, and Cache
ipconfig /flushdns
Remove-Item "$env:TEMP\*" -Recurse -Force
Clear-RecycleBin -Force
Restart Network Adapters
Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | Disable-NetAdapter -Confirm:$false
Start-Sleep -Seconds 5
Get-NetAdapter | Enable-NetAdapter -Confirm:$false
Check System Health & Disk
sfc /scannow
DISM /Online /Cleanup-Image /RestoreHealth
chkdsk C: /scan
Enable High Performance Power Plan
powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61
powercfg -setactive e9a42b02-d5df-448d-aa00-03f14749eb61