Solved

Adding PhoneNumber via DSADD

Posted on 2007-12-04
3
259 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now