System Maintenance Utility Script
Hi guys,
I made a simple PowerShell script using Copilot, that runs a utility that will help you clean your computer. Simply run PowerShell as administrator and paste the code below into it. Thanks.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Create Form
$form = New-Object System.Windows.Forms.Form
$form.Text = "System Maintenance Utility By Samuel Herrera Version 1.0 2026"
$form.Size = New-Object System.Drawing.Size(400,500)
$form.StartPosition = "CenterScreen"
# --- BUTTON: Clean Temp Files ---
$btnTemp = New-Object System.Windows.Forms.Button
$btnTemp.Text = "Clean Temp Files"
$btnTemp.Size = New-Object System.Drawing.Size(180,40)
$btnTemp.Location = New-Object System.Drawing.Point(110,30)
$btnTemp.Add_Click({
$paths = @(
"$env:TEMP\*",
"C:\Windows\Temp\*",
"C:\Windows\Prefetch\*"
)
foreach ($path in $paths) {
try { Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue } catch {}
}
[System.Windows.Forms.MessageBox]::Show("Temp files cleaned successfully!")
})
$form.Controls.Add($btnTemp)
# --- BUTTON: Clear Recycle Bin ---
$btnRecycle = New-Object System.Windows.Forms.Button
$btnRecycle.Text = "Clear Recycle Bin"
$btnRecycle.Size = New-Object System.Drawing.Size(180,40)
$btnRecycle.Location = New-Object System.Drawing.Point(110,90)
$btnRecycle.Add_Click({
try {
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
[System.Windows.Forms.MessageBox]::Show("Recycle Bin cleared!")
}
catch {
[System.Windows.Forms.MessageBox]::Show("Unable to clear Recycle Bin.")
}
})
$form.Controls.Add($btnRecycle)
# --- BUTTON: Disk Defragmenter ---
$btnDefrag = New-Object System.Windows.Forms.Button
$btnDefrag.Text = "Run Disk Defrag"
$btnDefrag.Size = New-Object System.Drawing.Size(180,40)
$btnDefrag.Location = New-Object System.Drawing.Point(110,150)
$btnDefrag.Add_Click({
Start-Process "dfrgui.exe"
})
$form.Controls.Add($btnDefrag)
# --- BUTTON: Run SFC /scannow ---
Recommended by LinkedIn
$btnSFC = New-Object System.Windows.Forms.Button
$btnSFC.Text = "Run SFC /scannow"
$btnSFC.Size = New-Object System.Drawing.Size(180,40)
$btnSFC.Location = New-Object System.Drawing.Point(110,210)
$btnSFC.Add_Click({
Start-Process powershell -Verb RunAs -ArgumentList "/c sfc /scannow"
})
$form.Controls.Add($btnSFC)
# --- BUTTON: Clear Temporary Internet Files ---
$btnInternet = New-Object System.Windows.Forms.Button
$btnInternet.Text = "Clear Internet Temp Files"
$btnInternet.Size = New-Object System.Drawing.Size(180,40)
$btnInternet.Location = New-Object System.Drawing.Point(110,270)
$btnInternet.Add_Click({
# Internet Explorer / Legacy Edge
$iePaths = @(
"$env:LOCALAPPDATA\Microsoft\Windows\INetCache\*",
"$env:LOCALAPPDATA\Microsoft\Windows\WebCache\*"
)
# Edge Chromium
$edgePath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache\*"
# Chrome
$chromePath = "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*"
# Firefox (multiple profiles)
$firefoxRoot = "$env:APPDATA\Mozilla\Firefox\Profiles\"
$firefoxPaths = @()
if (Test-Path $firefoxRoot) {
$firefoxPaths = Get-ChildItem $firefoxRoot -Directory | ForEach-Object { "$($_.FullName)\cache2\*" }
}
$allPaths = $iePaths + $edgePath + $chromePath + $firefoxPaths
foreach ($path in $allPaths) {
try { Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue } catch {}
}
[System.Windows.Forms.MessageBox]::Show("Temporary Internet Files cleared!")
})
$form.Controls.Add($btnInternet)
# --- BUTTON: Check Disk (CHKDSK) ---
$btnCHK = New-Object System.Windows.Forms.Button
$btnCHK.Text = "Run Check Disk"
$btnCHK.Size = New-Object System.Drawing.Size(180,40)
$btnCHK.Location = New-Object System.Drawing.Point(110,330)
$btnCHK.Add_Click({
Start-Process powershell -Verb RunAs -ArgumentList "/c chkdsk C: /f"
})
$form.Controls.Add($btnCHK)
# Show Form
$form.Topmost = $true
$form.Add_Shown({$form.Activate()})
[void]$form.ShowDialog()