Solved

Diskpart batch script that outputs multiple volume labels to variables

Posted on 2011-03-10
1
2,063 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

22 Experts available now in Live!

Get 1:1 Help Now