T3RRY wrote: ↑09 Jun 2020 12:50
wmic output takes a little more work, refer to the remarks for more.
Well, thanks to your code and explanations I was able to achieve what I needed, thank you.
In fact I have extended it to provide two more outputs as below.
The first one [ CODE 1 ] is your one and works perfectly.
My question is please, is there a way to condense the
FOR loops or is the way I have done it correct?
Code: Select all
:: ------------ SETUP LF & SPACING
(set LF=^
%= newline variable =%)
set "SPACING= "
:: ------------ CODE 1
for /f "usebackq delims=" %%a in (`"wmic logicaldisk get caption, volumename"`) do (
for /f "delims=" %%b in ("%%a") do (
if not "%%b"=="" set "Volume_Name=!Volume_Name!!SPACING:~0,1!%%b!LF!"
)
)
:: ------------ CODE 2
for /f "usebackq delims=" %%a in (`"wmic diskdrive get Model, MediaType, SIze, Partitions, Index, InterfaceType"`) do (
for /f "delims=" %%b in ("%%a") do (
if not "%%b"=="" set "Disk=!Disk!!SPACING:~0,1!%%b!LF!"
)
)
:: ------------ CODE 1
for /f "usebackq delims=" %%a in (`"wmic /namespace:\\root\wmi path MSStorageDriver_FailurePredictStatus"`) do (
for /f "delims=" %%b in ("%%a") do (
if not "%%b"=="" set "Fail_Predict=!Fail_Predict!!SPACING:~0,1!%%b!LF!"
)
)
Then I use these variables . . .
Code: Select all
!Volume_Name!
!Disk!
!Fail_Predict!
They all work but I wondered if there was a way to nest the FOR loops so there is not so much code in case I want to add one or two at a later date?
Thanks in advance.