Skip to content

Instantly share code, notes, and snippets.

@michaelsanford
Last active December 14, 2024 04:43
Show Gist options
  • Save michaelsanford/b74359375a617122bcf375efa20f41b6 to your computer and use it in GitHub Desktop.
Save michaelsanford/b74359375a617122bcf375efa20f41b6 to your computer and use it in GitHub Desktop.
Windows 11 Maintenance (DISM, SFC, compact VM disks)
#Requires -RunAsAdministrator
wsl --shutdown
chkdsk.exe /scan C:
DISM /Online /Cleanup-Image /RestoreHealth
sfc /scannow
Optimize-Volume -NormalPriority -Verbose -DriveLetter C
Get-ChildItem -Path $Env:LOCALAPPDATA -Recurse -Filter *.vhdx -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "Optimizing VHD: $($_.FullName)"
Optimize-VHD -Path $_.FullName -Mode Full
}
Get-ChildItem -Path "$Env:HOMEPATH\VirtualBox VMs" -Recurse -Filter *.vdi -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "Compacting: $($_.FullName)"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium "$($_.FullName)" --compact
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment