Very simple and quick way to attach or detach a VHD file on demand, from the command line – use diskpart;
A) Create a diskpart script to attach your VHD;
Enter the following into a new text document (for the sake of argument, let’s call this attach-script.txt)
select vdisk file="your.vhd"
attach vdisk
B) Create a batch file to execute the diskpart script;
Invoke diskpart with the /s parameter as follows in your batch file (again, let’s call this attach.bat)
diskpart /s attach-script.txt
C) Create a diskpart script to detach your VHD;
Should be as follows (calling this detach-script.txt)
select vdisk file=”your.vhd”
attach vdisk
Create a batch file to execute the diskpart script;
As before, call diskpart with /s (detach.bat)
diskpart /s detach-script.txt
And your done…. just execute attach or detach as needed to mount/unmount your vhd file….
Shouldn't the second line of the script in part C) read "detach vdisk"?
ReplyDeleteyes
Delete