# BATCH Store WMI Query with multiple conditions into variable



## lancastert (Apr 5, 2007)

Hi All

I am using this line in a batch script which successfully stores a user's SID value into a variable called SID


```
FOR /F "tokens=1,2 delims==" %%s IN ('wmic path win32_useraccount where name^='%_curruser%' get sid /value ^| find /i "SID"') DO SET SID=%%t
```
I'd like to modify this to include an "AND" in the WMI Query but I can't seem to get it to work.

The correct query is:


```
wmic path win32_useraccount where "name='%USERNAME%' and Domain like 'HB%'" GET SID /VALUE
```
Can someone please help me translate this so the SID value is stored into a variable?

Thanks!!!!!


----------



## foxidrive (Oct 20, 2012)

lancastert said:


> 'HB%'"


You have an unbalanced % in the variable name and also an unbalanced double quote - no matching partner.


----------



## djjarvis (Apr 18, 2005)

lancastert said:


> Hi All
> 
> I am using this line in a batch script which successfully stores a user's SID value into a variable called SID
> 
> ...


You're using % as a wildcard in the WMI query but command shell is interpreting that as the start of an environment variable. Try escaping the % using a carat (^)


----------

