
Find user in AD and add them to group
I have not done very many AD searches so this may not be the easiest way
but you can try this approach using ADO:
'************************************************************
Const ADSI_PROVIDER = "ADSDSOObject"
Const ADSI_PROV_NAME = "Active Directory Provider"
Dim strQuery
Dim varName
Dim lErrorNumber
Dim strTotal
Dim cmd 'ADODB.Command
Dim lcnt
Dim tmp 'IADsUser
Dim m_pConn 'ADODB.Connection
Dim m_recordSet 'ADODB.Recordset
Set cmd = CreateObject("ADODB.Command")
Set m_pConn = CreateObject("ADODB.Connection")
m_bLoggedOnUser = True
'
' Setup the connection
' replace <UserName> with the user ID to created the connection under
' replace <Password> with the password of the user ID
'
'
m_pConn.Provider = ADSI_PROVIDER
m_pConn.Properties("Encrypt Password") = False
m_pConn.Properties("User ID") = "<UserName>"
m_pConn.Properties("Password") = "<Password>"
m_pConn.Open ADSI_PROV_NAME
'
' Setup the command object
'
Set cmd.ActiveConnection = m_pConn
'
' Set the query string
' Substitute your server name for mdblackadder
' and your base DN for "dc=dutradomain,dc=testserver,dc=test"
' Replace <SamName> with the samAccountName to search for
'
'
strQuery = "Select AdsPath, CN From
'LDAP://mdblackadder/dc=dutradomain,dc=testserver,dc=test' Where " & _
"objectClass='user' And samaccountname='<SamName>'"
WScript.Echo Len(strQuery) & ":" & strQuery
cmd.CommandText = strQuery
cmd.Properties("Page Size") = 10
'
' Execute the command
'
Set m_recordSet = cmd.Execute
WScript.Echo m_recordSet.RecordCount
While (Not m_recordSet.EOF)
WScript.Echo m_recordSet.Fields("AdsPath")
m_recordSet.MoveNext
Wend
'*********************************************************************
Mike Dutra
Windows Script Host Support
This posting is provided AS IS with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.
--------------------
Quote:
>X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
>Subject: Re: Find user in AD and add them to group
>Thanks, for the info. I'd like to search through all OU's, find the user
>account and add it to a specified group as you scripted.
>Thanks,
>Aaron
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!