→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Jono
Champion Sweeper II
Hello,

I would like to create a custom user action to set or change the user's telephone number. I know that the attribute in AD is "telephoneNumber" but I don't know VBScript well enough to know how to set or change an attribute.

From there, I think it would be easy enough to set or change any of the attributes by simply changing the code to that attribute.

Ideally, I'd like to be able to click on the custom action, have it ask me for the telephone number, and then set it in AD. I would then like the script to read that attribute and show it to me in a MsgBox.

I'm thinking it would be simple enough. I imagine it would be similar to the Change Description script for changing a computer description.

Any help would be greatly appreciated.

Jono
9 REPLIES 9
nmulder
Engaged Sweeper
The phone number change works perfect for computers in the current domain where the script runs from. When I run the script on a user that is in a different domain I get an error about BOF and EOF are true, or the record has been deleted. I am guessing that this is because it is pulling the domain that it is running from and that user is not in it. How do I specify a different domain name to use this on those users on different domains.

Thanks,
Nick
Jono
Champion Sweeper II
nmulder wrote:
The phone number change works perfect for computers in the current domain where the script runs from. When I run the script on a user that is in a different domain I get an error about BOF and EOF are true, or the record has been deleted. I am guessing that this is because it is pulling the domain that it is running from and that user is not in it. How do I specify a different domain name to use this on those users on different domains.

Thanks,
Nick

Hi Nick - I have no idea how to specify a domain. We only have one here, so this issue hasn't come up. But certainly someone in this forum would have the answer.

Can anyone help Nick?

Thanks,
Jono
RumbleZilla
Engaged Sweeper II
That worked right out of the gate!!!!

Your help just became a highlight of my day 🙂
I appreciate the help, Jono!
Jono
Champion Sweeper II
Hi Mark,

Here's what I use (filename is ChgDesc.vbs):
Set WshNetwork = WScript.CreateObject("WScript.Network")

strComputer = Wscript.Arguments.Item(0)
strDescription = Inputbox("Enter Description:")

Set Obj= GetObject("winmgmts:\\" & strComputer).InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = strDescription
x.Put_
Next

WScript.Quit

... with this as the action:
cscript {actionpath}ChgDesc.vbs {computer}

I hope this helps.

Jono
RumbleZilla
Engaged Sweeper II
Thank you for this great script. It works like a champ!

Is there a way to change this script to modify the computer description?
I had used that other script http://www.lansweeper.com/forum/yaf_postst417_Change-the-computer-description.aspx in a previous network but since moving on to another employer, Lansweeper moved on to version 5. Now the Change Computer Description script no longer works.
Did something change within Lansweeper's new version to prevent this for working?

Thanks in advance,
Mark
danscallon
Engaged Sweeper II
I notice that this adds an x (for extension I suppose) to the phone number.
Is there a way to remove the x?

example:

I want
(970)204-5555

instead of
x(970)204-5555

Solved-I removed the x from this portion of the script

' 3
objUser.Put "telephoneNumber", " " & strExt
objUser.SetInfo
On Error GoTo 0
End If
Jono
Champion Sweeper II
danscallon wrote:
I notice that this adds an x (for extension I suppose) to the phone number.
Is there a way to remove the x?

example:

I want
(970)204-5555

instead of
x(970)204-5555

Yes, I use this for extensions. Try changing the first objUser line in section 3. It'll look like this:
' 3
objUser.Put "telephoneNumber", strExt
objUser.SetInfo

By the way, since I did this over a year ago, I wanted to be able to clear out the telephone number (removing the contents) without having to use a space or anything else. If you don't enter anything in the input box, it will assume that you don't want the telephone number changed and it won't change anything. So I edited the code to give the option of clearing it out; it will then quit the script.

Add an additional IF statement after the "strExt = Inputbox..." line and before the "If Not adoRecord..." in section 2:
' 2
strExt = Inputbox("Enter Extension:","Enter Extension",objUser.telephoneNumber)

If strExt = "9" Then
objUser.PutEx ADS_PROPERTY_CLEAR, "telephoneNumber", 0
objUser.SetInfo
MsgBox "Extension has been cleared."
Wscript.Quit
End If

If Not adoRecord.EOF Then
On Error Resume Next

I hope this helps.

Jono
Jono
Champion Sweeper II
OK, I found out how to do it. Here's the code.

Option Explicit
Dim strUser, rootDSE, adoConnection, ldapStr, adoRecord, objUser, strExt, objExt, strMsg, choice

' Change the attribute in the 4 numbered locations and save as new VBS.

struser = WScript.Arguments(0)

Set rootDSE = GetObject("LDAP://RootDSE")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "ADs Provider"

ldapStr = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=Person)(objectClass=User)(samAccountName=" & strUser & "));adspath;subtree"

Set adoRecord = adoConnection.Execute(ldapStr)
Set objUser = GetObject (adoRecord.Fields(0).Value)

' 1

strMsg = "The current extension is: " & objUser.telephoneNumber & VbCrLf & VbCrLf & _
"Do you want to change this user's extension in AD?"

choice = MsgBox(strMsg,4,"Change Extension?")

If choice = 6 Then

' 2

strExt = Inputbox("Enter Extension:","Enter Extension",objUser.telephoneNumber)

If Not adoRecord.EOF Then
On Error Resume Next

' 3
objUser.Put "telephoneNumber", "x" & strExt
objUser.SetInfo
On Error GoTo 0
End If

End If

'Set objExt = GetObject("LDAP://" & objUser.distinguishedName)

' 4

MsgBox "Extension: " & objUser.telephoneNumber,0,"User's Extension"


The custom user action is this:
{actionpath}scriptName.vbs "{username}"

Whenever you want to create a new script for a different attribute, change the attribute name in the 4 numbered locations and rename it as a new VBS file (and create a new custom action, of course).
Jono
Champion Sweeper II
I thought I'd found it, but I'm having some problems. The code below worked one time and then stopped working. It acts like it's skipping the IF statement now. No errors, but nothing gets changed.

Any help?

Option Explicit
Dim strUser, rootDSE, adoConnection, ldapStr, adoRecord, objUser, objExt, strExt

struser = WScript.Arguments(0)
strExt = Inputbox("Enter Extension Number:")

Set rootDSE = GetObject("LDAP://RootDSE")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "ADs Provider"

ldapStr = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=Person)(objectClass=User)(samAccountName=" & strUser & "));adspath;subtree"

Set adoRecord = adoConnection.Execute(ldapStr)
If Not adoRecord.EOF Then
On Error Resume Next
Set objUser = GetObject (adoRecord.Fields(0).Value)
objUser.Put "telephoneNumber", "x" & strExt
objUser.SetInfo
On Error GoTo 0
End If

Set objExt = GetObject("LDAP://" & struser)
MsgBox objExt.telephoneNumber


Thanks,
Jono