There is probably a better way to do the search than using the array like I am, but I can't think of another way right now.
'==========================================================================
'
' NAME: searchAndmodifyUser.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL:
' DATE : 2/27/2004
'
' COMMENT: <comment>
'
'==========================================================================
Dim ENT_OU(3)
Const LDOMAIN = "LDAP://DomainName/"
ENT_OU(0) = "OU=firstOU,DC=company,DC=com"
ENT_OU(1) = "OU=secondOU,DC=company,DC=com"
ENT_OU(2) = "OU=thirdOU,DC=company,DC=com"
UID = "Administrator"
PWD = "PasswordOfAdminID"
username = InputBox("Enter Username to Modify","Edit Account?")
set objUser = GetUser2(userName)
objUser.AccountDisabled = False
objUser.SetInfo
Public Function GetUser2(ByVal sAMAccountName)
Dim ADCon,ADCmd,ADRec,str
Set ADCon = CreateObject("ADODB.Connection")
Set ADCmd = CreateObject("ADODB.Command")
ADCon.Provider = "ADsDSOObject"
ADCon.Open "Active Directory Provider", UID, PWD
Set ADCmd.ActiveConnection = ADCon
ADCmd.Properties("Cache results") = False
ADCmd.Properties("TimeOut") = 120
For x = 0 To 2
str = "select sAMAccountName, ADsPath " & _
"from '" & LDOMAIN & ENT_OU(x) & "' " & _
"where objectCategory='person' and sAMAccountName='" & sAMAccountName & "'"
Next
ADCmd.CommandText = str
Set ADRec = ADCmd.Execute()
If ADRec.EOF Then
Set objUser = Nothing
Exit Function
End If
' Then bind to the IADs object.
Set GetUser2 = getObject(ADRec.Fields("adspath"))
End Function
I hope you find this post helpful. Please let me know if it was.
Regards,
Mark