james_higgs
asked on
Diskpart batch script that outputs multiple volume labels to variables
Hello Everyone,
I have the following script that runs diskpart on a Win 2k3 SP2 machine and looks for specific volume labels then returns the volume number that I use later in the script.
I did see that someone already posted something almost identical but then went away from the batch script and went to vb..
The problem with my script is that diskpart is run separately for each line - since volume numbers change, the output is not consistent and some volume labels return the same volume #. Is there a way to run the diskpart command only once but still be able to query against all the different criteria and still set the variables?
Here is the script:
set SCRIPTLOC=d:\scripts
echo Assigning Drive Letters
:: Create a script file to be used by the for loops
echo list volume > %SCRIPTLOC%\Listvols.tmp
:: Parse the output from 'Diskpart> list volume' for drives
echo Checking for volume SysDB...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp') DO @IF /I "%%c" == "SysDB" @SET XDrive=%%b
echo Checking for volume Quorum...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp') DO @IF /I "%%c" == "Quorum" @SET MDrive=%%b
echo Checking for volume DbBLogs...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp') DO @IF "%%c" == "DbBLogs" @SET WDrive=%%b
echo Checking for volume DbB...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp') DO @IF "%%c" == "DbB" @SET LDrive=%%b
Thanks in advance!!!!
I have the following script that runs diskpart on a Win 2k3 SP2 machine and looks for specific volume labels then returns the volume number that I use later in the script.
I did see that someone already posted something almost identical but then went away from the batch script and went to vb..
The problem with my script is that diskpart is run separately for each line - since volume numbers change, the output is not consistent and some volume labels return the same volume #. Is there a way to run the diskpart command only once but still be able to query against all the different criteria and still set the variables?
Here is the script:
set SCRIPTLOC=d:\scripts
echo Assigning Drive Letters
:: Create a script file to be used by the for loops
echo list volume > %SCRIPTLOC%\Listvols.tmp
:: Parse the output from 'Diskpart> list volume' for drives
echo Checking for volume SysDB...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp')
echo Checking for volume Quorum...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp')
echo Checking for volume DbBLogs...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp')
echo Checking for volume DbB...
FOR /F "tokens=1-4" %%a IN ('diskpart /s %SCRIPTLOC%\Listvols.tmp')
Thanks in advance!!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.