Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query for pre-existing sAMAccountName

Status
Not open for further replies.

DougInCanada

Technical User
Feb 1, 2004
98
CA
I have a script for creating a new user object, but I need to be able to check for any pre-existing sAMAccountName in my Active Directory.

Id ther a simple way to query my entire AD domain to check for any existing occurrences or do I have to query each possible specific OU?

Cheers?
 
When I try to add a duplicate name, the script kicks out this error:

Error: The object already exists
Code: 80071392
Source: (null)

The error is generated when I try to perform the objUser.SetInfo and the sAMAccountName already exists.

Is there any way to perform error handling using this error code so that I can alter the sAMAccountName, then re-run my code without getting the error message pop-up?
 
Hi DougInCanady & Welcome to Tek-Tips!

I'm fairly certain I've done this exercise in the past so I'm likely to have some code floating around somewhere but it might take me a while to find it. On the upside, I've found what I believe will work for you via a quick Google search.
Assuming the results don't change, the first and fourth links look like they'll do exactly what you need it to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top