There is an easy method to check that several nested commands have the right number of parentheses. Just indent each nested command three spaces to the right, place the opening left parentheses in the same line, and place the closing right parentheses in the same column of the command that it closes. For example
for %%a in (set) do (
for %%b in (set) do (
if %%a equ %%b (
then part
) else (
else part
)
)
)
When I apply such format to your code, I got this:
for /f "tokens=1" %%G in (termlist.txt) do (
for /f "Tokens=*" %%a in ('dsquery user -samid %%G^|dsget user -disabled^| Find /v "disabled"^| Find /v "dsget succeeded"') do set disable=%%a
)
echo "%%G %disable%" >> termvalid.txt)
This way, it is now evident that there is an additional right parentheses (that is ignored), but that the %%G is placed outside its FOR. There are two ways to fix this problem; eliminating the right parenteses and move the ECHO to the right place:
for /f "tokens=1" %%G in (termlist.txt) do (
for /f "Tokens=*" %%a in ('dsquery user -samid %%G^|dsget user -disabled^| Find /v "disabled"^| Find /v "dsget succeeded"') do set disable=%%a
echo "%%G !disable!" >> termvalid.txt
)
... or insert the missed left parentheses:
for /f "tokens=1" %%G in (termlist.txt) do (
for /f "Tokens=*" %%a in ('dsquery user -samid %%G^|dsget user -disabled^| Find /v "disabled"^| Find /v "dsget succeeded"') do (
set disable=%%a
)
echo "%%G !disable!" >> termvalid.txt
)
... besides of the problem that %disable% must be accessed via delayed !variable! expansion, because it is inside a FOR command.