The command executed by FOR /F goes through extra parsing that converts all unquoted/unescaped cmd.exe token delimiters into spaces. So WHERE LocalPath="value"
becomes
WHERE LocalPath "value"
.
You can escape the =
for /f "tokens=*" %q IN (
'WMIC /Node^:Comp1 PATH Win32_UserProfile WHERE LocalPath^="C:\\users\\ABC1" GET Status ^| find /V "Status" '
) do set pat= %q
Or you can enclose the entire WHERE clause in double quotes and then use single quotes for the value (this is my preferred way to write WHERE clauses with WMIC when used with FOR /F)
for /f "tokens=*" %q IN (
'WMIC /Node^:Comp1 PATH Win32_UserProfile WHERE "LocalPath='C:\\users\\ABC1'" GET Status ^| find /V "Status" '
) do set pat= %q
I don't think the :
really needs to be escaped, but I don't see how it can do any harm either.
You can run into the same problem when selecting multiple values with WMIC in a for /F - the unquoted/unescaped commas are turned into spaces. But in these cases quoting is not an option - you must escape the commas.
Something like this will not work:
for /f "delims=" %%A in ('wmic ...... get value1,value2,value3') do ...
You must escape the commas:
for /f "delims=" %%A in ('wmic ...... bet value1^,value2^,value3') do ...
EDIT
Well actually, there is a trick that sometimes allows you to completely eliminate all escaping. Since the command executed by FOR /F is executed via CMD /C, you can take advantage of the fact that CMD /C will strip enclosing double quotes.
So something like the following will work without any escapes as long as the keyword
doesn't have any characters that need escaping (it isn't quoted during the first round of parsing)
for /f "delims=" %%A in (
'"wmic .... where this='x' and that='y' get value1,value2,value3 | find "keyword"'
) do ...