WMIC output property value without property name

cmd.exeenvironment-variableswmic

I'm entering something like that

Desktop>wmic environment where(name="PATH" and systemVariable=FALSE) get variableValue
VariableValue
xxx

But I don't want VariableValue to get into output. I want simply get xxx
Is it possible?

Best Answer

I don't want VariableValue to get into output. I want simply get xxx Is it possible?

Using a batch file:

@echo off
setlocal
for /f "usebackq skip=1 tokens=*" %%i in (`wmic environment where ^(name^="PATH" and systemVariable^=FALSE^) get variableValue ^| findstr /r /v "^$"`) do echo %%i
endlocal

Using a command line:

for /f "usebackq skip=1 tokens=*" %i in (`wmic environment where ^(name^="PATH" and systemVariable^=FALSE^) get variableValue ^| findstr /r /v "^$"`) do @echo %i

Notes:

  • for /f loops through the wmic output.
  • skip=1 skips the header line (containing VariableValue)
  • findstr /r /v "^$" removes the trailing blank line from the wmic output.

Example output:

C:\Users\DavidPostill\AppData\Roaming\npm

Further Reading

Related Question