Not Exchange related, but something I’d like to share with you is a script to bulk configure and enable users for OCS with enterprise voice. In the process, the telephone numbers are also changed, since often the customer is moving to a new range of numbers as well.
The information was provided by the customer in an Excel sheet, which I exported to a CSV file. Since the script was to be run on an Windows Server 2003 box, I opted for a simple VB script, which you can find below.
A short explanation:
- When the telephone number has a value, the user is configured for enterprise voice (intOptionFlags 896). If the telephone number is empty, the user is configured for IM and presence (intOptionFlags 256);
- You can expand the sheet (CSV) with extra columns. When you need to create colums before the current ones, don’t forget to modify the index of the arrFields() references accordingly;
- Change the OCSHomeServer to the proper pool value;
- Change the OCSLocationProfile to the proper value;
- Change the OCSPhoneContext to the proper value;
- If you want to see what it will do first, set TestMode to True;
- Use it in a lab environment first; test, test, test!
Note: If you have problems finding out the value of the OCSHomeServer, OCSLocationProfile or OCSPhoneContext settings, configure one user with the proper settings using ADUC, and inspect the values of those settings by using ADSIEdit or LDP.
users.csv
name;samaccountname;telephonenumber Francis Blake;francis.blake;+31 (0) 30 123 45 11 Philip Mortimer;philip.mortimer;+31 (0) 30 123 45 22
OCSEnableUsers.vbs
'*-------------------------------------------------------------------------------- '* Name : OCSEnableUsers '* Created By : Michel de Rooij '* E-mail : michel@eightwone.com '* Date : 20101118 '* Version : 0.1 '*-------------------------------------------------------------------------------- '* Changes: '* 0.1 Initial version '*-------------------------------------------------------------------------------- On Error Resume Next dim oConn, strQry, rs, objUser, strVal, objFSO, objFile, strLine, arrFields, i, line dim strSAM, strTel dim strServerURI, strLineURI, strSIP, strExtension, intOptionFlags Const ADS_PROPERTY_APPEND = 3 Const OCSHomeServer = "CN=LC Services,CN=Microsoft,CN=OCSPOOL1,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso,DC=com" Const OCSLocationProfile= "CN={820ADF85-B64C-4F32-92F0-E4AA37267677},CN=Location Profiles,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso,DC=com" Const OCSPhoneContext = "L0CDP.L1UDP@OCS2.contoso.com" Const TestMode = False set oConn= createObject("Adodb.Connection") oConn.provider = "AdsDSOObject" oConn.open "ADs Provider" set objFSO= createObject("Scripting.FileSystemObject") set objFile= objFSO.OpenTextFile("users.csv", 1, True) wscript.echo "RUNNING IN TESTMODE IS "& TestMode line= 1 while not objFile.AtEndOfStream strLine= trim(objFile.readline) if Line> 1 Then arrFields= split(strLine, ";") strSAM= arrFields(1) strTel= normalizePhone( arrFields(2)) strTelNew= replace( replace( arrFields(3), "(0)", ""), " ", " ") wscript.echo strSAM&" "& strTel strQry= "<LDAP://dc=contoso,dc=com>;(samAccountName="& strSAM& ");adspath;subtree" set rs= oConn.execute( strQry) if rs.recordCount > 0 Then while not rs.EOF set objUser= getObject( rs.fields(0).value) wscript.echo "User found: "& objUser.distinguishedName wscript.echo "Previous Phone No: "& objUser.TelephoneNumber strSIP= "sip:"& objUser.mail strExtension= right( strTel, 3) strLineURI= "tel:"& strTel& ";ext="& strExtension strServerURI= "sip:"& strExtension& ";phone-context="& OCSPhoneContext If strTel= "" Then intOptionFlags= 256 Else setAttr objUser, "msRTCSIP-Line", strLineURI setAttr objUser, "msRTCSIP-LineServer", strServerURI intOptionFlags= 896 End If ' Set AD fields setAttr objUser, "telephoneNumber", strTelNew ' Set OCS props setAttr objUser, "msRTCSIP-UserEnabled", True setAttr objUser, "msRTCSIP-PrimaryHomeServer", OCSHomeServer setAttr objUser, "msRTCSIP-PrimaryUserAddress", strSIP setAttr objUser, "msRTCSIP-UserLocationProfile", OCSLocationProfile setAttr objUser, "msRTCSIP-OptionFlags", intOptionFlags addAttr objUser, "proxyAddresses", strSIP If Not TestMode Then objUser.SetInfo End If rs.moveNext wend Else wscript.echo "*** WARN: User not found in AD: "& strSAM End If Else ' Skip header End If line= line+ 1 wend objFile.close set objFSO= Nothing Function setAttr( objUser, strAttr, strVal) wscript.echo "Setting "& strAttr& " to "& strVal If TestMode Then ' ... Else objUser.put strAttr, strVal End If End Function Function addAttr( objUser, strAttr, strVal) wscript.echo "Adding "& strVal& " to "& strAttr If TestMode Then ' ... Else objUser.PutEx ADS_PROPERTY_APPEND, strAttr, array(strVal) End If End Function Function NormalizePhone( Tel) NormalizePhone= replace( replace( tel, " ", ""), "(0)", "") End Function