Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
jrhodes1 Respected Contributor.
Respected Contributor.

Imaging script wiping all drives not just primary


I have a small problem with our current windows 10 imaging script (see below), everything works fine normally but when we image a machine with more than 1 drive in both drives get wiped (we know this is because of img –pd all) and quite often the secondary drive will end up with the image on and not the primary. Therefore, can someone please tell me of a way of forcing the imaging process to only wipe and image the primary drive.

As a side note the entire imaging system and this script was originally written by our previous network manager who has now left but sadly he wasn’t the best at doing documentation, I am almost sure I know how it all works but there are a couple of things I am not fully sure about.

zisedit computername=

img -pd all
img -pc1 -type=ntfs -size=450 -guid=WRE
img -pc2 -type=fat32 -size=100 -guid=ESP
img -pc3 -type=1 -size=16 -guid=MRP
img -pc4 -type=ntfs -guid=MBD
img -pa1
img -pa2
img -pa3
img rp $PROXYADDR $baseimage.zmg -ap=a1:p1 -ap=a2:p2 -ap=a3:p3 -ap=a4:p4
img rp $PROXYADDR $driverimage.zmg -ap=a1:p4
img rp $PROXYADDR FirstBoot2.zmg -ap=a1:p4
reboot –f

Any help you can give me is very much appreciated.



Any advice on making this script work better or if there is a better way of imaging a machine will be very much appreciated as well.

Labels (1)
2 Replies
Micro Focus Expert
Micro Focus Expert

Re: Imaging script wiping all drives not just primary

Yes, instead of telling it to delete all partitions, you would just want to specify the numbers 1 thru 4.

The issue about restoring to the OTHER disk is that the DISK0 may not be the bootable disk.

Your system could have one disk on SATA Port 2.  Add a Second Disk later on SATA Port 1, then it would be the 1st disk and where everything would be created.

Fixing this would be much trickier, as you would need your script to query the existing drives and partitions and then logically delete and recreate partitions based upon that.

WinPE supports all "IMG" commands and perhaps with Powershell you could divine which partitions you want to go where based upon your existing image.

To try and build a testing environment, I would likely build a VM with 2 Virtual Disks.  Disk1=2GB and Disk2=500MB.   Then install Windows on Disk 2.  This would likely be your "Worse Case scenario" and you would need your script to be able to detect this and perhaps restore partitions 2-5 vs 1-4.

That being said....it may even get trickier as the Boot files in this case may STILL go to Disk1 even though Windows is on disk 2.  Thus JUST restoring disk 2 may not be valid.

This was a scenario I had with my last build......and after the fact I had to issue various Windows commands to make sure my SSD actually contained all the boot files as well.  This would likely be external to imagining, where you may or may not need to fix existing devices so that all the boot files are actually on the Windows drive.

Sorry...no simple answer once you get to the case where the 1st Drive is not the Windows Drive  and the secondary drive may or may not contain the required boot files.



Please give a hearty thumbs up to any post you find helpful!
To find articles by Craig Wilson simply follow the link: Craig Wilson's Tips!
jrhodes1 Respected Contributor.
Respected Contributor.

Re: Imaging script wiping all drives not just primary

Thanks for the info I will have a look into it and see what I can come up with to try and fix our problems.  We do always try to make sure that our primary drive is in the primary/lowest numbered SATA port in every machine.

One of the problems we had recently with the imaging was there was an SD card in the machine (I did not even see it) and the imaging process decided that was the drive to put windows on I did not even think it would detect an SD card but it did.  I imaged that machine 3 times wondering what was going on before I finally found the SD card.

Again thanks for the info.


The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.