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
Solved

script to add machines to correct OU

Posted on 2013-12-03
7
173 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Computer account cleanup 90 127
Reset server 2008 R2 default permissions 2 22
Auto-launch VPN via Wifi 7 49
Need VBA code to change date format of Column A 5 23
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

792 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