Skip to content
  • How to start learning Linux
  • Labtech Implementation Stuff
  • Clogged
  • Active Directory DNS Troubleshooting
  • Some Roulette  Strat from Reddit
  • Mystery steel processing and testing
  • Croissants and Rose Lychee Cream
  • Mac and Cheese
  • DFS Replication: Requirements and Configuration
  • Services.msc not opening in Windows 11/10
  • Microsoft AD LDAP (2008): Importing Your Certificate .pfx File into the AD DS Personal Store
  • Powershell How to get all groups that a user is a member of?
  • Home Energy Saving Tips
  • Changing NTFS Security Permissions using PowerShell
  • VALORANT’S 128-TICK SERVERS

Merserver

Its a website

  • Uncategorized
  • IT
  • Unreal Engine
  • GameDev
  • Interesting Stuff
  • Food
  • Web Design
  • Kubernetes
  • Music
  • Linux
  • Toggle search form

Compact/Shrink a Bloated VHDX (Hyper-V VM Drive) in Powershell

Posted on January 8, 2021 By samadmin

The virtual hard drive “compact” option offered in the Hyper-V menu frees little or no space. Here’s a better way.

Log into the VM and clear out any noticeable junk (temp folder, recycle bin, browser cache, incomplete downloads, etc).

Back up VM, then shut down.

In the HV, open the VM’s settings and make a note of where its vhdx is stored. Run PowerShell as an Administrator.

In PowerShell, run these commands.

Mount-VHD -Path “path to vhdx” -ReadOnly

Optimize-VHD -Path “path to vhdx” -Mode Full

(note: sometimes full mode is ineffective for some reason. If it appears to takes under 5 minutes to run a full optimization, try Quick instead.)

Dismount-VHD “path to vhdx”

Be sure to replace “path to vhdx” with the full path including drive letter.

Start up the VM and log in to make sure nothing broke.

Uncategorized

Post navigation

Previous Post: Clearing out binlogs mysql
Next Post: Configuring Hyper-V Replication

Related Posts

Disabling “Other Suggestions” in Outlook 2016 Uncategorized
Home Energy Saving Tips Uncategorized
Adding a Software Token to an eclinicalworks Account Uncategorized
Restricting Specific Web Sites in Internet Explorer Using Group Policy Uncategorized
pfsense + squid + Kerberos Uncategorized
How to export and import a User Profile in Dragon NaturallySpeaking Uncategorized

Copyright © 2025 Merserver.

Powered by PressBook Masonry Dark