Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding PhoneNumber via DSADD

Posted on 2007-12-04
3
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
LauraEHunterMVP earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
Six Sigma Control Plans
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

721 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