Solved

script to add machines to correct OU

Posted on 2013-12-03
7
169 Views
Last Modified: 2014-09-09
Im looking for a free program or script that will move machines into the correct OU. We are imaging machines and are not using sys prep anymore. I am not responsible for the image just responsible for after the machines are on the domain. Thanks.
0
Comment
Question by:Thomas N
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Expert Comment

by:Jason Watkins
ID: 39692886
Can you pre-stage the accounts in the domain before they computers are imaged? That's what I do.
0
 

Author Comment

by:Thomas N
ID: 39692962
We would like to do it after we have the machines are on the domain. Preferably using a script I could give to the techs to run after they image a machine.
0
 
LVL 27

Expert Comment

by:Jason Watkins
ID: 39693003
0
Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

 
LVL 65

Expert Comment

by:RobSampson
ID: 39694307
Hi, do you have rules that define the "correct" OU, or is it one static OU?  If the latter, the script Firebar pointed to should work.  If not, you could present a list of pre-defined OUs, using an InputBox in VBScript, or a drop-down box in an HTA.

Rob.
0
 

Author Comment

by:Thomas N
ID: 39695781
Hi rob. Its not a static OU. It goes to different OU's depending on the site they are at. Can you show me step by step instructions to do this? Thanks
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 39696971
Right, so as an example, you can try this VBS code.  I'm assuming the computer is already in AD joined to the domain?

On the dctSites.Add lines, you can change the "Site Name" that comes from AD Sites and Services (which will have IP Ranges associated with them), and then move a computer based on which site they're in, to the OU you specify for that site.

Regards,

Rob.

Set dctSites = CreateObject("Scripting.Dictionary")
dctSites.CompareMode = vbTextCompare

dctSites.Add "Site1", "OU=Computers,OU=Site1,DC=domain,DC=com"
dctSites.Add "Site2", "OU=Computers,OU=Site2,DC=domain,DC=com"

Set objADSysInfo = CreateObject("ADSystemInfo")
strComputer = objADSysInfo.ComputerName
strSite = objADSysInfo.SiteName
If dctSites.Exists(strSite) = True Then
	strNewOU = dctSites(strSite)
	On Error Resume Next
	Set objOU = GetObject("LDAP://" & strNewOU)
	If Err.Number = 0 Then
		On Error GoTo 0
		WScript.Echo "Moving " & strComputer & " to " & strNewOU
		intReturn = objOU.MoveHere("LDAP://CN=atl-ws-01,OU=Finance,DC=fabrikam,DC=com", vbNullString)
		If intReturn = 0 Then
			WScript.Echo "Move successful."
		Else
			WScript.Echo "Move failed with return code " & intReturn & "."
		End If
	Else
		WScript.Echo "Error binding to target OU of " & strNewOU & ". Error " & Err.Number & ": " & Err.Description
		Err.Clear
		On Error GoTo 0
	End If
Else
	WScript.Echo strSite & " does not have an associated OU."
End If

Open in new window

0
 

Author Comment

by:Thomas N
ID: 39732085
Ok I will try it.
0

Featured Post

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now