Write Last Logged On User to The Managed By Field in Active Directory

I am looking for a script that will write the last logged on user to the Manged by field in Active Directory for my computers. I would like to run it as both a logoff and shutdown script. My goal is to be able to search active directory for the username and see the last computer they logged onto.

Thank you for your help!
LVL 22
Joseph MoodyBlogger and wearer of all hats.Asked:
Who is Participating?
 
PberSolutions ArchitectCommented:
Try this:

Set objSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)

objComputer.Put "managedBy", objSysInfo.Username
objComputer.SetInfo

Open in new window

0
 
PberSolutions ArchitectCommented:
There is no field called Managed by?  Could you be referring to: manager or masteredBy?
 
Have you seen this solution here: http://blogs.technet.com/heyscriptingguy/archive/2005/04/29/how-can-i-change-the-user-and-computer-account-description-attributes-each-time-a-user-logs-on.aspx
It writes the logon info to the description field, but it could be modified to output to a different field.
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
You are on the ball today!

I tried that script before and it works great but I would rather the service tag be placed in the description. I attached an image where I think it would make the most sense to go. Do you know of a better place?
Untitled.jpg
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
snusgubbenCommented:
Another way to achieve this without writing attributes is just to make a logon/logoff script that output the info you like to a log file located on a share.

http://support.microsoft.com/kb/556015

SG
0
 
PberSolutions ArchitectCommented:
That is actually the Manager field and it has to contain the distinguished name of the user.  Give me a bit to modify the scirpt
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
I've looked at outputting it to a share as well. My goal is to get all of the common information that was spread across many sources into active directory so that it is fully searchable and interconnected. For example, if a user calls me and says that their desktop is saying memory bad. I can look up the computer the user last logged onto and grab the service tag all from active directory.
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thanks Pber! You are awesome!
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
That works but could it be set up so that the owner just reads their name instead of the entire path of their user?
0
 
PberSolutions ArchitectCommented:
The ManagedBy field is defined as a Distinguished Name field.  You can't just put plain text in there.  That is how it displays and it can't be changed.
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thought that would be the answer. It works for me though!
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thanks again!
0
 
PberSolutions ArchitectCommented:
Sorry about the display format, but glad to help.
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Nothing that you can do about it and it works perfectly!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.