Solved

Diskpart batch script that outputs multiple volume labels to variables

Posted on 2011-03-10
1
2,053 Views
Last Modified: 2012-05-11
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!!!!
0
Comment
Question by:james_higgs
1 Comment
 

Accepted Solution

by:
james_higgs earned 0 total points
ID: 35100717
Hello Everyone,

I ended up just outputting diskpart to file and then parsed the file which maintained consistency.

Changed diskpart /s %SCRIPTLOC%\Listvols.tmp to type %SCRIPTLOC%\diskpartoutput.tmp in the above script.


Thanks!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now