Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • Last Modified:

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

0
Joseph Moody
Asked:
Joseph Moody
  • 3
  • 2
  • 2
  • +1
1 Solution
 
YZlatCommented:
can I see your script for renaming computer?
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
I was referring to renaming a computer by hand. (for example, if a machine is moved to another location).
0
 
RobSampsonCommented:
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.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Daz_1234Commented:
Does it need to be done in the logoff script?  What's wrong with doing it in the logon script?

Daz.
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
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.

0
 
Daz_1234Commented:
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.
0
 
RobSampsonCommented:
Could you have different domain controllers that the PC might connect to that are not in sync?
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Script actually runs fast. Moved to user side
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.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now