Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Adding PhoneNumber via DSADD

I get an error message when I try to add a phonenumber to a users profile.

Error: Object does not support this proberty or method: 'tel'.
Code:800A01B6

According to microsoft and others 'tel' is the right proberty to use when you want to get/write to the PhoneNumber field. (http://technet2.microsoft.com/windowsserver2008/en/library/9e274947-2dec-4448-a822-8dd2f688fcec1033.mspx?mfr=true)

Any ideas?
BTW it does the same when trying to add iptel (IP telephonenumber) and dept (Department)

Regards
Kasper
Option Explicit
 
Const ADS_PROPERTY_CLEAR = 1
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
 
Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strProfilePath, strCellNumber
Dim strPhoneNumber, strDirect, strDept
Dim objUser, strUserNTName
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain
 
' Check for required arguments.
If (Wscript.Arguments.Count < 1) Then
    Wscript.Echo "Argument <SpreadsheetName> required. For example:" _
        & vbCrLf _
        & "cscript UpdateUserProfile2.vbs c:\MyFolder\UserList.xls"
    Wscript.Quit(0)
End If
 
' Spreadsheet file.
strExcelPath = Wscript.Arguments(0)
 
' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If
On Error GoTo 0
 
' Open spreadsheet.
On Error Resume Next
objExcel.Workbooks.Open strExcelPath
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Spreadsheet cannot be opened: " & strExcelPath
    Wscript.Quit
End If
On Error GoTo 0
 
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
 
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
 
' Use the NameTranslate object to find the NetBIOS domain name
' from the DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, _
    Len(strNetBIOSDomain) - 1)
 
' The first row of the spreadsheet is skipped (column headings). Each
' row after the first is processed until the first blank entry in the
' first column is encountered. The first column is the NT user name of
' the user, the second column is the new profilePath. The loop binds to
' each user object and assigns the new value for the attribute. intRow
' is the row number of the spreadsheet.
' Use the NameTranslate object to convert the NT user names
' to the Distinguished Name required for the LDAP provider.
intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
    strUserNTName = Trim(objSheet.Cells(intRow, 1).Value)
    ' Use NameTranslate to convert NT name to Distinguished Name.
    On Error Resume Next
    objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strUserNTName
    If (Err.Number <> 0) Then
        On Error GoTo 0
        Wscript.Echo "User " & strUserNTName _
            & " not found in Active Directory"
    End If
    On Error GoTo 0
    strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
    ' Escape any forward slash characters, "/", with the backslash
    ' escape character. All other characters that should be escaped are.
    strUserDN = Replace(strUserDN, "/", "\/")
 
    strCellNumber = Trim(objSheet.Cells(intRow, 2).Value)
    strPhoneNumber = Trim(objSheet.Cells(intRow, 3).Value)
    
    'Sets the Cellphone number
    If (strCellNumber <> "") Then
        On Error Resume Next
        Set objUser = GetObject("LDAP://" & strUserDN)
        If (Err.Number <> 0) Then
            On Error GoTo 0
            Wscript.Echo "User NOT found " & strUserDN
        Else
            On Error GoTo 0
            If (LCase(strCellNumber) = ".delete") Then
                On Error Resume Next
                objUser.PutEx ADS_PROPERTY_CLEAR, "mobile", 0
                objUser.SetInfo
                If (Err.Number <> 0) Then
                    On Error GoTo 0
                    Wscript.Echo "Unable to clear CellPhoneNumber for user " _
                        & strUserDN
                End If
                On Error GoTo 0
            Else
                objUser.mobile = strCellNumber
                On Error Resume Next
                objUser.SetInfo
                If (Err.Number <> 0) Then
                    On Error GoTo 0
                    Wscript.Echo "Unable to set CellPhoneNumber for user " _
                        & strUserDN
                End If
                On Error GoTo 0
            End If
        End If
    End If
'****** IT IS THIS PART THAT FAILS ******
    'Sets the Phone number
    If (strPhoneNumber <> "") Then
        On Error Resume Next
        Set objUser = GetObject("LDAP://" & strUserDN)
        If (Err.Number <> 0) Then
            On Error GoTo 0
            Wscript.Echo "User NOT found " & strUserDN
        Else
            On Error GoTo 0
            If (LCase(strPhoneNumber) = ".delete") Then
                On Error Resume Next
                objUser.PutEx ADS_PROPERTY_CLEAR, "hometel", 0
                objUser.SetInfo
                If (Err.Number <> 0) Then
                    On Error GoTo 0
                    Wscript.Echo "Unable to clear PhoneNumber for user " _
                        & strUserDN
                End If
                On Error GoTo 0
            Else
                objUser.hometel = strPhoneNumber
                On Error Resume Next
                objUser.SetInfo
                If (Err.Number <> 0) Then
                    On Error GoTo 0
                    Wscript.Echo "Unable to set PhoneNumber for user " _
                        & strUserDN
                End If
                On Error GoTo 0
            End If
        End If
    End If
    
 
    intRow = intRow + 1
Loop
 
' Close the workbook.
objExcel.ActiveWorkbook.Close
 
' Quit Excel.
objExcel.Application.Quit
 
' Clean up.
Set objUser = Nothing
Set objExcel = Nothing
Set objSheet = Nothing
Set objRootDSE = Nothing
Set objTrans = Nothing
 
Wscript.Echo "Done"

Open in new window

0
Kasper Katzmann
Asked:
Kasper Katzmann
  • 2
1 Solution
 
LauraEHunterMVPCommented:
That would be because you're not using DSADD, you're using VBScript.  dsadd is a command-line script that uses the -tel switch to add a phone number, but this does not mean that "tel" is the name of the attribute in question.

The two telephone number attributes that I can think of are:

telephoneNumber
facsimileTelephoneNumber

For a complete list of attribute names, open up a user object within ADSI Edit; you will see a list of all available attributes and the correct name for each.
0
 
LauraEHunterMVPCommented:
Correction..."dsadd is a command-line _utility_", not a script.
0
 
Kasper KatzmannAuthor Commented:
Thank's a lot :-) Excellent solution.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now