All,
Hello. I am needing to query AD for the Computer Name tied to a particular sAMAccountName, but cannot figure out how to do it. I know this has to be simple, but it escapes me.
I use the following function to pull other info by the sAMAccountName, but the "ComputerName" returns null. I've also tried "logonWorkstation", but returns null as well. Can anyone please help?
Hello. I am needing to query AD for the Computer Name tied to a particular sAMAccountName, but cannot figure out how to do it. I know this has to be simple, but it escapes me.
I use the following function to pull other info by the sAMAccountName, but the "ComputerName" returns null. I've also tried "logonWorkstation", but returns null as well. Can anyone please help?
Code:
Function GetInfoByRACF(ByVal racf As String, ByVal req As String) As String
Dim user
On Error Resume Next
Set rs = CreateObject("adodb.recordset")
rs.ActiveConnection = "provider = adsdsoobject"
rs.Open "<LDAP://dc=xxxxxx,dc=com>;(samaccountname=" & racf & ");adspath;subtree"
If Not rs.EOF Then
Set user = GetObject(rs(0))
Select Case LCase(req)
Case "name"
GetInfoByRACF = user.get("displayname")
Case "phone"
GetInfoByRACF = user.get("telephonenumber")
Case "name2"
GetInfoByRACF = user.get("givenname")
Case "mgr"
GetInfoByRACF = user.get("extensionattribute8")
Case "cost_center"
GetInfoByRACF = user.get("departmentnumber")
Case "email"
GetInfoByRACF = user.get("msRTCSIP-PrimaryUserAddress")
Case "comp"
GetInfoByRACF = user.get("ComputerName")
Case Else
GetInfoByRACF = ""
End Select
End If
Set rs = Nothing
End Function