I like to store any sort of confidential data on my usb flash drive, such as passwords, backups of my bussiness database etc. But I’m just a human and can lost my drive once… So I create virtual disk, encrypt it with BitLocker and put to flash. Google tells a lot of guides how to create/format it, but this post not about that. Task is attach vdisk without opening disk manager.
This batch generate script with current drive letter (%~d0) and execute it by diskpart.
ECHO SELECT VDISK FILE = "%~d0\vdrive_1gb.vhd" > %tmp%\.tmp
ECHO ATTACH VDISK >> %tmp%\.tmp
DISKPART /s %tmp%\.tmp
DEL %tmp%\.tmp /Q