DSQUERY - how to find if a user doesnt exists from a list

Hi,

I am trying to write a script that will check each userID on a list to see if it still exists in AD (the list is a txt file showing just a userID per line).

So far I have written in my script:

for /F "tokens=1" %%a in (source.txt) do (
dsquery user dc=d2-tdbfg,dc=com -samid "%%a"
)


but I am missing the part where it checks if the value returned is NULL then write something like "user X doesnt exist"

I am hoping that someone can kindly show me how to write it using for /f or vbscript. Thank you.
LVL 1
elchermansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CoralonCommented:
Something like this should work..

for /F "tokens=1" %%a in (source.txt) do (
if A%%aA = A(dsquery user dc=d2-tdbfg,dc=com -samid "%%a")A (echo User %%a Exists!) else (echo User %%a does *not* exist)
)

Open in new window


It might need a little tweaking, (I'm on my home machine, so I can't test the dsquery part).

Coralon
0
elchermansAuthor Commented:
Hi Coralon,

It doesnt work, it returns:

C:\scripts>usersexists.bat
= was unexpected at this time.

C:\scripts>if %a = A(dsquery user dc=d2-tdbfg,dc=com -samid "%a")A (echo User %a
 Exists!) else (echo User %a does *not* exist)

and thats it
0
CoralonCommented:
Whoops.. that first = sign should be ==

for /F "tokens=1" %%a in (source.txt) do (
if A%%aA == A(dsquery user dc=d2-tdbfg,dc=com -samid "%%a")A (echo User %%a Exists!) else (echo User %%a does *not* exist)
)

Open in new window


Coralon
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.