Back to User management: Other
DESCRIPTION
I used this function to get a DN of a user via the samAccountName so that I could set that as a manager field in AD when Quick Connect Job runs. Provided by Alexi Vereschaga (av@qu[[ars-script-wiki&mce_rdomain=dell.com:mailto:av@quest.com|]]e[[ars-script-wiki&mce_rdomain=dell.com:mailto:av@quest.com|]]st.com)
NOTES
Obviously, replace the "EDMS://w2003svrI2/DC=w2003I,DC=ver" with your own path.
Note This code may use functions from the ARS Script Policy Best Practices. Please, follow the link to obtain instructions and code for those functions.
SCRIPT
'*********************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT QUEST PROFESSIONAL SERVICES.
'*********************************************************************************
'
' This code is published on the ActiveRoles Script Center:
' http://communities.quest.com/docs/DOC-9991
'
' This code may use functions from the ARS Script Policy Best Practices:
' http://communities.quest.com/docs/DOC-10016
'
' Please, follow the link to obtain instructions and code for those functions.
'*********************************************************************************
Function GetCurrentManager(strUserIDManager)
Dim oConnect
Dim Command
Dim rs
' Create the Connection object and load the OLE DB provider
Set oConnect = CreateObject("ADODB.Connection")
oConnect.Provider = "ADsDSOObject"
' Set the ADSI Flag property to 32768
oConnect.Properties("ADSI Flag") = 32768
' Validate user credentials ("", "" means that the current user credentials are used)
oConnect.Open "DS Query", "", ""
' Create the Command object
Set Command = CreateObject("ADODB.Command")
' Maintain an active connection
Set Command.ActiveConnection = oConnect
' Specify the search string (SQL syntax)
Command.CommandText = _
"SELECT ADsPath FROM 'EDMS://w2003svrI2/DC=w2003I,DC=ver' WHERE objectClass = 'user' AND sAMAccountName = '"&strUserIDManager&"'"
' Set additional properties of the search string
Command.Properties("Page Size") = 2
Command.Properties("Timeout") = 30 'seconds
Command.Properties("searchscope") = 10 'ADS_SCOPE_ONELEVEL
' Start the search
Set rs = Command.Execute
Dim usr, dn
' Process the search results
If Not rs.EOF Then
' Bind to the found user object using its ADsPath property
Set usr = GetObject(rs.Fields("ADsPath").Value)
GetCurrentManager = usr.Get("distinguishedName")
Else
GetCurrentManager = ""
End If
End Function
'***** END OF CODE ***************************************************************
COMPATIBILITY
Script compatible with the following version(s): <Not specified>