Testing if a user exists in a domain
This depends on how many users you will be looking for. If you are checking for just one user the method you use is fine. If you will need to check for the existence of several users I would enumerate the domain collection and place the results in an array. Then filter the array for searches.
Check it out
http://cwashington.netreach.net
Win32 bit scripting. Everything you need to get up and running,
A script repository containing almost 100 sample scripts,
downloads, reference files, and technical support via an
online discussion forum.
(Pursuant to US Code, Title 47, Chapter 5, Subchapter II, 227, any and all
unsolicited commercial E-mail sent to this address is subject to a download
and archival fee in the amount of $1000 US. E-mailing denotes acceptance of
these terms.)
Hi,
I need to test if a username already exists within a domain as part of a
user management script I am writing. At the moment, I am doing it with a
code snippet like this one:
.....
Dim objDomain ' an ADSI domain object, initialised elsewhere in my code
Dim objUser ' an ADSI user object
Dim blnExists ' does the user exist?
blnExists = False
objDomain.Filter = Array("user")
for each objUser in objDomain
wscript.echo objUser.name
if objUser.name = strUsername then blnExists = True : exit for
next
.....
So, if the user exists, blnExists will be True. However, this method means
that in the worst case I have to enumerate the entire list of domain users
in order to find out if just one user exists, which seems less than
efficient. :)
Is there a way I can quickly test for the existance of just one user in the
domain? (Something rather than "user" as the filter, maybe?)
Thanks,
Zack
--
User Support Officer
Lancaster City Council, UK