?
Solved

script to add machines to correct OU

Posted on 2013-12-03
7
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Determining the an SCCM package name from the Package ID
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Suggested Courses

762 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