Link to home
Start Free TrialLog in
Avatar of Joseph Moody
Joseph MoodyFlag for United States of America

asked on

Managed By Script Modification

As a logoff script, we copy the last logged on user to the managed by attritbute for that computer account. When we rename the computer, we get an error in the script saying that the specified account does not exist. Then the computer takes 10 minutes to shut down the group policy client service.

How can the script be modified to prevent this?

Set objSysInfo = CreateObject("ADSystemInfo") 
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) 
 
objComputer.Put "managedBy", objSysInfo.Username 
objComputer.SetInfo

Open in new window

Avatar of YZlat
YZlat
Flag of United States of America image

can I see your script for renaming computer?
Avatar of Joseph Moody

ASKER

I was referring to renaming a computer by hand. (for example, if a machine is moved to another location).
Do you rename the account in Active Directory, or on the physical computer?  The only reason I can think that is says the computer doesn't exist, is maybe there's slow replication between your domain controllers, and they don't all have the same renamed computer account.  When you get this problem, connect to each DC and check whether the computer exists, and run this on the system:

Set objSysInfo = CreateObject("ADSystemInfo")
WScript.Echo "LDAP://" & objSysInfo.ComputerName

manually, to see whether the computer is correct.

Rob.
ASKER CERTIFIED SOLUTION
Avatar of Darren Collins
Darren Collins
Flag of United Kingdom of Great Britain and Northern Ireland 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
It occurs when we renamed the account on the physical machine.

I will try it on logon to see. We are normally asked to keep scripts on logoff to help with the logon time.

I would think that the snippet you posted would be quick so it will not noticeably delay the logon process.

Let's see: Try this for testing:

t = timer
Set objSysInfo = CreateObject("ADSystemInfo") 
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) 
 
objComputer.Put "managedBy", objSysInfo.Username 
objComputer.SetInfo
Msgbox "took " & timer - t & " seconds."

Open in new window


Daz.
Could you have different domain controllers that the PC might connect to that are not in sync?
Script actually runs fast. Moved to user side