Last active
December 14, 2024 04:43
-
-
Save michaelsanford/b74359375a617122bcf375efa20f41b6 to your computer and use it in GitHub Desktop.
Windows 11 Maintenance (DISM, SFC, compact VM disks)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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