Figure out which Drive to Image in your Startnet.cmd file

email me

This script will determine whether C, D, or E drive is the proper drive to image during an automated imaging process. This is important if you have multiple partitioned drives and would like to automate the imaging—for example, you have C drive for Windows, D drive for data, and E drive for recovery. They will not necessarily be those letters during the imaging process, so you need a way to determine which is the right drive letter for the Windows drive (otherwise, you risk imaging the wrong partition—yikes). I use diskpart to format the Windows partition (the easy part)…and the script returns each drive’s available space, all except the Windows drive (since it was formatted)…an empty drive returns “c:\”

@echo off
title Windows 7 Imaging Utility
cls
Echo Please wait while the Imaging Utility loads....
color 0a
@setlocal enableextensions enabledelayedexpansion
wpeinit

set MyDrv=

rem this images the drive
if exist d:\boot\wim\image.wim (
cls
echo Running diskpart on drive...
diskpart /s d:\boot\wim\disk.txt

for /f "tokens=3" %%a in ('dir c:\') do set varDrv1=%%a
for /f "tokens=3" %%c in ('dir e:\') do set varDrv3=%%c

set varDrv1=!varDrv1:,=!
set varDrv3=!varDrv3:,=!

if !varDrv3! EQU e:\ echo success && set MyDrv=E
if !varDrv1! EQU c:\ echo success && set MyDrv=C

cls
echo Imaging drive...please wait
d:\boot\wim\imagex.exe /apply d:\boot\wim\image.wim 1 !MyDrv!:
goto :end
)

rem this images the drive
if exist e:\boot\wim\image.wim (
cls
echo Running diskpart on drive...
diskpart /s e:\boot\wim\disk.txt

for /f "tokens=3" %%a in ('dir c:\') do set varDrv1=%%a
for /f "tokens=3" %%b in ('dir d:\') do set varDrv2=%%b

set varDrv1=!varDrv1:,=!
set varDrv2=!varDrv2:,=!

if !varDrv2! EQU d:\ echo success && set MyDrv=D
if !varDrv1! EQU c:\ echo success && set MyDrv=C

cls
echo Imaging drive...please wait
e:\boot\wim\imagex.exe /apply e:\boot\wim\image.wim 1 !MyDrv!:
goto :end
)

rem this images the drive
if exist f:\boot\wim\image.wim (
cls
echo Running diskpart on drive...
diskpart /s f:\boot\wim\disk.txt

for /f "tokens=3" %%a in ('dir c:\') do set varDrv1=%%a
for /f "tokens=3" %%b in ('dir d:\') do set varDrv2=%%b
for /f "tokens=3" %%c in ('dir e:\') do set varDrv3=%%c

set varDrv1=!varDrv1:,=!
set varDrv2=!varDrv2:,=!
set varDrv3=!varDrv3:,=!

if !varDrv3! EQU e:\ echo success && set MyDrv=E
if !varDrv2! EQU d:\ echo success && set MyDrv=D
if !varDrv1! EQU c:\ echo success && set MyDrv=C

cls
echo Imaging drive...please wait
f:\boot\wim\imagex.exe /apply f:\boot\wim\image.wim 1 !MyDrv!:
goto :end
)

:end
exit