Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

script to add machines to correct OU

Posted on 2013-12-03
7
Medium Priority
?
177 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

610 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