Link to home
Start Free TrialLog in
Avatar of elchermans
elchermansFlag for Canada

asked on

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.
Avatar of Coralon
Coralon
Flag of United States of America image

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
Avatar of elchermans

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Coralon
Coralon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial