0

I am trying to get a user's SIP address so I can use a JavaScript object to check their presence in Office Communicator. Here is a script I found that is similar to what I am looking to do.

Option Explicit
DIM objConnection, objCommand
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection 

Dim objOU, objUser, strUPN, strSIP, SIPLine
' Bind to the OU object.
Set objOU = GetObject("LDAP://chkenergy.net/DC=chkenergy,DC=net")

' Enumerate all users in the OU.
objOU.Filter = Array("user")
For Each objUser In objOU
' Skip computer objects.
 If (objUser.Class = "user") Then
  strUPN = objUser.userPrincipalName
  strSIP = objUser.get("msRTCSIP-PrimaryUserAddress")

  wscript.echo strSIP

End If

Next

Basically, I can get their username from AD, and I would like to pass that in and get their SIP address (strSIP) back. Is there a way to fix this code to do that task specifically?

Mark Cheek
  • 265
  • 2
  • 10
  • 20
  • Can you give a bit more detail about what you're trying to achieve? Will this code run on a users machine, and get their own presence? or will it get another users presence? Will communicator be installed on the machine running this code? Where does javascript com into it? Just trying to understand if there may be a better approach than going to AD – Paul Nearney Jan 26 '11 at 15:58
  • JavaScript comes into it because it is the main logic source of this application. The application returns an on-call rotation schedule to the user, and I want to integrate each of those users' communicator presence into that schedule. I use the NameCtrl.GetStatus JS method to get their presence. I need their SIP address to pass into that method so I am assured it is the correct address. Let me know if you need anything else – Mark Cheek Jan 26 '11 at 17:23
  • AH, ok - makes sense. @Harvey's answer below should be perfect, then – Paul Nearney Jan 27 '11 at 10:17

1 Answers1

0

The problems of your posted vbscript are

  1. It enumerates the user on the client side, which will take a lot of time to find the correct user. Similarly, instead of pulling all the records from the database and do the comparison on your client side, you would run a SQL query. Right?
  2. The enumeration is done at one single level only. You have to fix your code to do recursive enumeration. However, if you fix it to do recursive enumeration, it's going to take even longer time and even more resources to do your job.

Before I answer your question, here are some basic background knowlege on Active Directory.

  • User objects on Active Directory contains a number of attributes.
  • In particular, samAccountName is your pre-Windows 2000 name.
  • userPrincipalName is in the format of user@domain.name

You can actully execute a query using an ADO connection object. Since you are binded to an Active Directory, you can execute a LDAP query. The LDAP query string contains four parts.

  • Root path, where we start the search.
  • LDAP filter
  • Returned attributes
  • Search scope

The LDAP query string that you should use should be something like

<LDAP://chkenergy.net/DC=chkenergy,DC=net>;(&(objectClass=user)(samAccountName=yourusername));msRTCSIP-PrimaryUserAddress;subtree
  • The root path in the above example is <LDAP://chkenergy.net/DC=chkenergy,DC=net>.
  • The LDAP filter is (&(objectClass=user)(samAccountName=yourusername)). Of course, you need to replace yourusername to something else inside your code. I am assuming you can pass in a samAccountName. If that's not the case, you need to modify the filter yourself.
  • Returned attributes is msRTCSIP-PrimaryUserAddress. I think that's what you need. Right?
  • I am assuming you are trying to search for all user objects under the same domain. So, your search scope should be subtree

Here is a complete sample that I guess it should do your job

userName = "harvey"
ldapStr = "<LDAP://chkenergy.net/DC=chkenergy,DC=net>;(&(objectClass=user)(samAccountName=" & userName & "));msRTCSIP-PrimaryUserAddress;subtree"

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"
Set rs = conn.Execute(ldapStr)

While Not rs.EOF
   wscript.echo rs.Fields("msRTCSIP-PrimaryUserAddress")
   rs.MoveNext
Wend
Harvey Kwok
  • 11,713
  • 6
  • 37
  • 59
  • Everything is correct there except .Fields("samAccountName") should be .Fields("msRTCSIP-PrimaryUserAddress") because that is the variable I am trying to extract. Thanks though. – Mark Cheek Jan 27 '11 at 14:28