The wmi batch file set is displayed as a variable

Hi, when I first time with a BATCH script, I get the hard disk size as follows:

wmic diskdrive get size 

Which works fine, but I would like to store this value in a variable for later use, for example, using ECHO to display the value.

I'm not sure how to set the output of the above command to a variable. I went with:

 SET hddbytes=wmic diskdrive get size 

But that just sets the variable to the above text string, not the output.

+6
source share
3 answers

For use in a batch file. From the command line, replace %% with%

 for /f "tokens=*" %%f in ('wmic diskdrive get size /value ^| find "="') do set "%%f" echo %size% 

Or if you want to use your preferred variable

 for /f "tokens=2 delims==" %%f in ('wmic diskdrive get size /value ^| find "="') do set "myVar=%%f" echo %myVar% 
+9
source

Do you want to:

 for /f %%a in ('wmic diskdrive get size^|findstr [0-9]') do echo %%a 
+2
source
 for /f "delims=" %%w in ('wmic diskdrive get size /format:Textvaluelist.xsl') do for /f "usebackq delims=" %%a in ('%%w') do set %%a echo %size% 
0
source

Source: https://habr.com/ru/post/958866/


All Articles