@echo off rem counter variable set tempvar=1 rem get volumes that are optical drives echo list volume > diskpart_input.txt diskpart /s diskpart_input.txt > temp.txt find /n "-ROM" temp.txt > temp2.txt for /f "tokens=3,4 delims= " %%a in (temp2.txt) do ( if %tempvar%==1 ( echo tempvar is %tempvar% set tempvar= 2 echo changed tempvar to %tempvar% echo select volume= %%a > tempscript.txt echo assign letter=R >> tempscript.txt type tempscript.txt echo Assigning drive R diskpart /s tempscript.txt ) else ( echo select volume= %%a > tempscript.txt echo assign letter=S >> tempscript.txt echo Assigning drive S diskpart /s tempscript.txt goto end ) ) :end del /f temp.txt del /f temp2.txt del /f diskpart_input.txt del /f tempscript.txt pause