elchermans
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.
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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