I found these handy ways to mount/unmount a
vhd file in a command prompt / batch file.
However; that still leaves me with one question; assuming I'm specifying the file I want to mount directly; how do I find out what drive letter it was assigned using the command prompt?
So if I can go into
DiskPart and run the following commands:
DISKPART> select vdisk FILE="F:\WindowsImageBackup\leeand00-pc\Backup 2017-01-10 031515\924cde0a-0000-0000-0000-50c603000000.vhdx" DiskPart successfully selected the virtual disk file. DISKPART> ATTACH VDISK 100 percent completed DISKPART> LIST VOLUME Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- -------- Volume 0 E DVD-ROM 0 B No Media Volume 1 H DVD-ROM 0 B No Media Volume 2 SYSTEM RESE NTFS Partition 100 MB Healthy System Volume 3 C NTFS Partition 159 GB Healthy Boot Volume 4 F wbadmin_bac NTFS Partition 57 GB Healthy Volume 5 PQSERVICE NTFS Partition 15 GB Healthy Hidden Volume 6 G FreeAgent D NTFS Partition 1397 GB Healthy Volume 7 D Removable 0 B No Media Volume 8 NTFS Partition 159 GB Healthy DISKPART> ASSIGN LETTER=X There is no volume specified. Please select a volume and try again.
Then I can't assign the drive letter immediately to the newly attached volume...however, I can select it by calling it out by it's volume number:
DISKPART> SELECT Volume 8 Volume 8 is the selected volume. DISKPART> ASSIGN LETTER=X DiskPart successfully assigned the drive letter or mount point.
Seeing as I want to run this as a script...how is it that I can select the newly mounted
xvhd and assign it a drive letter?
People screw around with the drive letter system all the time, by mapping and unmapping shares, and by inserting / removing thumb drives.
So how can I safely do this considering the issues with the drive mapping being probably inconsistent, and the fact that when I create a system state backup, it doesn't assign my volume a label?
P.S. My goal here is to automate this so it can be called by a script, do a system state backup (which I've already succeeded at), and then mount the
xvhd of the drive, delete most of the user profiles from it (handled by a separate backup) and then unmount it so it can be backed up by another program, and restored to the machine in the event of a disaster; (also I would restore the user profiles from a separate backup).