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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing user accoutn attributes in many OUs 2

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
I have a sub which is meant to go through all the user accounts in the AD domain and check a given username, and other details against them. However, all it's doing is listing the OUs, not the user account objects within them.
Code:
Set objDomain = GetObject("LDAP://" & conDomainName)

Sub TestForDuplicateSamAccountName
    wscript.echo " Test uniqueness of the username '" & strPre2kLogon & "'"
	For Each objUser In objDomain
        wscript.echo "Pre2KLogon  ='" & lcase(objUser.Name) & "'" & vbCrLf &_
                     "SamAccount  ='" & lcase(objUser.SAMAccountName) & "'" & vbCrLf &_
                     "CommonName  ='" & lcase(objUser.CN) & "'" & vbCrLf &_
                     "SMTP        ='" & lcase(objUser.Mail) & "'" & vbCrLf &_
                     "UPN         ='" & lcase(objUser.UserPrincipalName) & "'" & vbCrLf &_
                     "DisplayName ='" & lcase(objUser.DisplayName) & "'"
		If LCase(objUser.Name) = LCase(strPre2kLogon) Then
            wscript.echo " Duplicate account name found!"
            SuggestAlternativeName
            Exit Sub
		End If
	Next
	'wscript.quit
End Sub

This simpler version of the sub only uses the NT4 attributes but can't return the same details, although it does at least work as far as it goes:
Code:
Sub TestForDuplicateSamAccountName
    Dim objDomainNT
    Set objDomainNT = GetObject("WinNT://" & conDomainName)
    objDomainNT.Filter = Array("user")
    wscript.echo " Test uniqueness of the username '" & strPre2kLogon & "'" 'strUserName
	For Each objUser In objDomainNT
        wscript.echo "Pre2KLogon  ='" & lcase(objUser.Name) & "'"
        If LCase(objUser.Name) = LCase(strPre2kLogon) Then
            wscript.echo " Duplicate account name found!"
            SuggestAlternativeName
            Exit Sub
		End If
	Next
	wscript.quit
End Sub
What gives?

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
It will leave all the entries in place if it's not equal to the new user's [blue]secondary[/blue] SMTP address. (Please be more exact... leaving out some qualification may mean very different thing!)
 
OK, to be absolutely precise, it's possible that the duplicate pre-existing smtp: address will be either a Primary SMTP address or a tertiary (or deeper!) smtp address. admittedly that that's not likely, but it is possible, and we all like our scripts to be as thorough and as safe a possible...

To summarise, the script must take what the new user's SMTP address will be, then check for and delete a pre-existing identical address in AD before assigning it to the new user.

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
Right, having read up on the code I think I see what you're doing. You're taking the original array of proxyAddresses, then creating a new array (less the duplicate smtp address) and assigning the contents of the new array back to proxyAddresses.

Cool.

As this code is going to delete data, I'm not going to test and implement until we have our virtual test environment in place to test against. Instead, for the meantime, the script will quit out without committing any changes to AD after prompting the operator to manually correct the duplication.

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top