3
1
I found these handy ways to mount/unmount a xvhd
or 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).
You should be able to use the
GET-DISKIMAGE filename.vhd | GET-DISK | GET-PARTITION
syntax and just incorporate it into the dynamic script to run with Powershell accordingly. I'm making an assumption you are familiar with batch scripts and Powershell but let me know if you need assist with that part -- this should an easy peezy task. – Pimp Juice IT – 2017-01-10T04:33:43.283Ah! Sorry I changed some stuff...about what I already tried...so you're saying I should use PowerShell instead? – leeand00 – 2017-01-10T04:36:01.203
1@leeand00 Just incorporate the Powershell commands into the batch script accordingly. I will add an updated example... give me a second... – Pimp Juice IT – 2017-01-10T04:42:01.287
@leeand00 No problem, I had to take care of some things so sorry for the wait. Hopefully that will help you be able to run from a batch script accordingly. I use it similar with other scripts for my needs in some cases. I've just told it to set the drive letter as a variable and then to do a
CD /D
to that path but you can also use it as"%DriveLetter%:\"
and use that for the drive letter part in your explicitly specified paths in your scripted logic. Let me know how it goes when you get to it. I commented out the ISO mount logic but left it there in case someone else uses ISO and needs it. – Pimp Juice IT – 2017-01-10T05:25:01.307