Force Unmounting a VHD in Windows10 ( without a restart )

458 Views Asked by At

There is a requirement to monitor a pool of 20 Servers. Each Servers create VHDs periodically to perform certain XYZ tasks and unmounts them safely. VHD mounting and unmounting scripts are legacy ones and are written in batch diskpart.exe and not Powershell

More often than ever stale VHDs would start to pile up in these servers over period of time (a week or so for several reasons). Is there a way to force unmount a VHD discarding any changes periodically as part of a cleanup routine?

  1. Diskpart is not effective
  2. Ejecting the drive or Unmounting from disk manager is not clean approach and sometimes throws errors if VHD is not properly unmounted
  3. Restarting the server is cleanest way but not preferred

Is there a way to force unmount VHD drives via powershell or inbuilt win10 tools even when .vhdx file is not available. Also is it a preferred approach to use powershell script over diskpart to avoid these kind of issues?

0

There are 0 best solutions below