How to filter/pipe wmi output from batch or command prompt

9,525

why dont you use the serialnumber to find your drive ? One possible solution saving the result of wmic in a file :

REM replace D4B12CD with your drive serialnumber

wmic logicaldisk get caption,volumeserialnumber |findstr D4B12CD > c:\temp\Hdd.txt 
for /f %%i in (c:\temp\hdd.txt) do set mydrive=%%i

REM now mydrive contains the letter of your drive
echo %mydrive%
Share:
9,525

Related videos on Youtube

MrMAG
Author by

MrMAG

merge keep

Updated on September 18, 2022

Comments

  • MrMAG
    MrMAG over 1 year

    I need to write a little script for a specific HDD.
    I use the following command to detect the HDD by size:

     C:\>wmic logicaldisk get size,freespace,caption | find "750153363456"
    
     E:       27996512256  750153363456
    

    Now I need to store the drive-letter from that output (in this case E:) into a variable. How can I do that?

  • Wally
    Wally over 10 years
    I think that if you don't want to do a serialnumber search, you could at least store the value in a text file as demonstrated here.