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.
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:
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]
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
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]