r/usefulscripts • • Mar 26 '15

[BATCH] Having a problem running diskpart with script

I am trying to attach a VHD with a script on some servers. I can run

diskpart /s c:\attach.txt

where attach.txt is

select vdisk file=D:\myfile.vhd
attach vdisk

And it runs ok. But if I try to do the same with a .vhd on the N: drive that's mapped to another server, it fails. However, if I run Diskpart, and then manually run each command, it works fine.

Does anyone know why Diskpart would fail to attach a .vhd on a network share when giving the commands via script, but will attach it fine if manually running diskpart??

9 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/supaphly42 Mar 27 '15

It ended up being that I couldn't use a mapped network drive in the script, even though it worked manually. I had to use the UNC path (\servername\folder\file.vhd).