WMIC output property value without property name
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 thewmic
output. -
skip=1
skips the header line (containingVariableValue
) -
findstr /r /v "^$"
removes the trailing blank line from thewmic
output.
Example output:
C:\Users\DavidPostill\AppData\Roaming\npm
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- findstr - Search for strings in files.
- for /f - Loop command against the results of another command.
- wmic - Windows Management Instrumentation Command.
To omit the header line, simply pipe the output to more
and tell it to omit the first line:
wmic environment where(name="PATH" and systemVariable=FALSE) get variableValue | more +1
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/more