Solved

Diskpart batch script that outputs multiple volume labels to variables

Posted on 2011-03-10
1
2,087 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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