Friday, June 7, 2019

cmd.exe - WMIC output property value without property name


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?


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


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...