Solved

script to add machines to correct OU

Posted on 2013-12-03
7
175 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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

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.

Question has a verified solution.

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

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
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…

705 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