Solved

Adding PhoneNumber via DSADD

Posted on 2007-12-04
3
261 Views
Last Modified: 2012-06-27
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
Comment
Question by:Kasper Katzmann
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
LauraEHunterMVP earned 500 total points
ID: 20402772
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
 
LVL 30

Expert Comment

by:LauraEHunterMVP
ID: 20402775
Correction..."dsadd is a command-line _utility_", not a script.
0
 

Author Closing Comment

by:Kasper Katzmann
ID: 31412578
Thank's a lot :-) Excellent solution.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question