Created
September 4, 2025 14:43
-
-
Save renshuki/39b6f32df69c27ae0938681076782180 to your computer and use it in GitHub Desktop.
Windows PowerShell script to compact WSL vdisk (and recover unused disk space)
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
# Shut down WSL | |
wsl --shutdown | |
# Define the diskpart commands | |
$diskpartCommands = @" | |
select vdisk file="C:\path\to\image.vhdx" | |
attach vdisk readonly | |
compact vdisk | |
detach vdisk | |
"@ | |
# Run diskpart with the commands | |
$diskpartCommands | diskpart | |
Write-Output "Done!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment