I am attempting to create a batch file which will take a list of users from a text file, run a dsquery against Active Directory to determine if the account has been disabled or not, and then output the results to a different text file containing the user ID and the status (yes/no) of whether they've been disabled or not.
I feel like I'm positioning the quotes or the parentheses incorrectly but I'm also not 100% sure if multiple 'for' statements can even be nested like this. Input much appreciated.
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)
Try this (use first line if you want to be sure you are not appending to an old unwanted file):