Reputation: 13
how can set the DeviceID in a variable? output here is empty :(
in cmd working :
D:\>wmic logicaldisk where drivetype=5 get deviceid, volumename | find "bunny"
F: bd50-bunny-comple
here is my bat:
@echo off
d:\bunny.iso
set isoname=bunny
for /f "delims=" %%a in ('wmic logicaldisk where DriveType^="5" Get DeviceID^,volumename ^|find "%isoname%"') do (
set %%a
)
echo %DeviceID%
echo %volumename%
Regards
Upvotes: 1
Views: 5914
Reputation: 38654
Something like this perhaps:
@Echo Off
For /F "Skip=1 Delims=" %%A In (
'"WMIC LogicalDisk Where (DriveType='5') Get DeviceID, VolumeName"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set "DID=%%B" & Set "VOL=%%C"
Echo Volume %VOL% is assigned to %DID%
Timeout -1
Upvotes: 0
Reputation: 18837
Based on Magoo's comment :
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
For /F "skip=1" %%a in ('wmic logicaldisk where DriveType^="5" Get DeviceID^,volumename') DO (
SET "line=%%a"
CALL :striptrailing
if not "!line!"=="" (
set "myvar=!line!"
goto :loop_end
)
)
::****************************************
:loop_end
ECHO %myvar%
pause & GOTO :EOF
::****************************************
:striptrailing
IF NOT DEFINED line GOTO :EOF
if "%line:~-1%"==" " GOTO striptrailing
GOTO :eof
::****************************************
Upvotes: 1