Lansweeper logo
Home Download Features Demo Buy now Help Support forum
 
    Most requested support articles:
  Lansweeper troubleshooting guide.
  The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
  WMI Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  How to configure the windows firewall using group policies.
  Support:  
 support@lansweeper.com  
Skype: Lansweeper  
  Mo-Fri 9h-17h CET  
Welcome Guest Search | Active Topics | Log In | Register

Untag as favorite
Set or Change AD User Attributes
Jono
#1 Posted : Tuesday, December 20, 2011 5:14:06 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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
Jono
#2 Posted : Tuesday, December 20, 2011 9:44:18 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
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?

Code:
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
Jono
#3 Posted : Tuesday, December 20, 2011 11:18:18 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 41
Location: Metro Detroit
OK, I found out how to do it. Here's the code.

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).
Users browsing this topic
Guest
Untag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Contact: E-mail Lansweeper - Skype : Lansweeper
Copyright 2004 - 2011 © Hemoco bvba