create_vmdk_from_usb.cmd 709 B

12345678910111213141516171819
  1. @echo off
  2. chcp 65001
  3. cls
  4. color A
  5. for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,volumename^,drivetype 2^>NUL`) do (
  6. if %%j equ 2 (
  7. @echo %%i is a USB drive. Creating virtual disk "%USERPROFILE%\.VirtualBox\%%k.vmdk"
  8. For /F Tokens^=2Delims^=^" %%A In ('WMIC LogicalDisk Where "DeviceID='%%i'" Assoc /AssocClass:Win32_LogicalDiskToPartition 2^>Nul^|Find "n."') Do (
  9. For /F Tokens^=2Delims^=^" %%B In ('WMIC Path Win32_DiskDriveToDiskPartition 2^>Nul^|Find "%%A"') Do (
  10. @echo %%B
  11. "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands createrawvmdk -filename "%USERPROFILE%\VirtualBox VMs\%%k.vmdk" -rawdisk %%B
  12. )
  13. )
  14. )
  15. )
  16. pause