Solved

Diskpart batch script that outputs multiple volume labels to variables

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing Git and chefdk via bat script 8 86
Debugging a shell script 3 31
ROBOFTP UNZIP 1 53
How to use a single FE file for users with different access versions? 8 35
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…

809 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