DESCRIPTION
This function can be used to get a DN of a user via the samAccountName so that a manager field can be set in Active Directory in Quick Connect or Active Roles Synchronization Service Workflow steps.
NOTES
Replace the "EDMS://w2003svrI2/DC=w2003I,DC=ver" with your own path.
Note This code may use functions from the Active Roles 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 MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.
'*********************************************************************************
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 ***************************************************************