Link to home
Start Free TrialLog in
Avatar of skrysiak
skrysiakFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Write to Active Directory profile using VBScript logon script?

At our head office we have several phones and networked PCs. On each desk there is a phone and a PC. The phones' extension numbers range from 10 up to 63; the PCs names are "Dell" appended with a number between 00 and 54 (e.g. "Dell13").

The users hot-desk; that is, John may use computer "Dell13" today while Jane uses "Dell14", but John may use "Dell14" tomorrow while Jane uses "Dell02" in another office, depending on which PC is free to use. The PCs and phones are never moved from the desks, so "Dell13" is always on the desk that can be reached on phone extension 24, and so on.

We're running a Windows 2003 client server with Windows XP PCs on the network. I use a simple VBScript logon script to map drives, printers and suchlike. Is it possible to use the logon script to get the computer name, match this to the desk's phone extension number from an array in the script, and then update the user's Active Directory profile with this extension number?

If this is possible, each time a user logs on their Active Directory profile will be updated to show their current phone extension number. Our administration team can then look-up a user's contact details on their Active Directory profile, making hot-desking users easier to contact by phone.

Unfortunately (due to the order in which our equipment was installed) the phone extension numbers do not correspond to the numbers in the PCs' names, possibly necessitating an array (or external CSV file) to hold these pairs.
Avatar of remmett70
remmett70
Flag of United States of America image

Quick question.  What to do if a users is logged on at multiple computers?
Avatar of Ashtear
Ashtear

I'm afraid I can't actually write the script for you, but...

You want to look at Windows Script host, mostly.  Grabbing the computer name is simple enough.  It's the ComputerName string that's part of the WScript.Network object.  So you create the object and then pull the computer name out as seen in the first part of the code snippet.

The second code snippet uses VBS to pull out a user account, then changes a couple phone numbers.  (Make sure to change the OU and DC variables, and make CN the user's account name. - You need an ou= for each organizational unit the user is in (Hopefully they are all in the same one), and read each DC= as having a dot between them )  

Hope this helps.
'Getting the computer name...
Set WshNetwork = WScript.CreateObject("WScript.Network")
MyComputerName = WshNetwork.ComputerName
 
'For setting the phone number...
Const ADS_PROPERTY_UPDATE = 2 
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") 
 
objUser.Put "homePhone", "(425) 555-0100"
objUser.Put "pager", "(425) 555-0101"
objUser.Put "mobile", "(425) 555-0102"
objUser.Put "facsimileTelephoneNumber", "(425) 555-0103"   
objUser.Put "ipPhone", "5555"
 
objUser.SetInfo

Open in new window

Avatar of skrysiak

ASKER

@remmett70:

A user will remain on the same computer for the session, and log off when they are done working.

It is unlikely that a user will be logged on at more than one computer simultaneously (there are rarely enough vacant computers here to do this!), but if they forget to log off on one computer and log on to another, their most recent logon will write their Active Directory profile with the extension number corresponding to the current desk/computer in in use.
Oh crap, I didn't mention, but the active directory code snippet (somewhat shortened) is from http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/usersgroups/users/  Originally.  Check there for the full version of the script and other scripts.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial