Advertisement

05.18.2006 at 01:35AM PDT, ID: 21854932
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

VBScript to Move AD Computers

Asked by jarjarbinx1979 in Visual Basic Programming

Tags: ,

What I am after is a script to move computers from one OU to another OU.  Why?  Well all new computers go to an "Unassigned" OU when they join the domain, then we have separate OU's for operating systems (2k and XP) so the script needs to determine the operating system then move to the correct OU for that operating system.  However it should not move servers.

I have searched the WEB and have created the below script, but it doesn't seem to be working correctly....if anyone can help it will be appreciated
JJB

=============================
Option Explicit

Dim objRootDSE, strDNSDomain, objCommand, objConnection
Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
Dim strDN, strOS, objW2kOU, objXPOU

' Bind to target W2k and XP OU containers.
Set objW2kOU = GetObject("LDAP://ou=2k,ou=workstations,ou=Computers,ou=OU,dc=MY,dc=DOMAIN,dc=COM")
Set objXPOU = GetObject("LDAP://ou=XP,ou=workstations,ou=Computers,ou=OU,dc=MY,dc=DOMAIN,dc=COM")


' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")


' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on all computer objects.
strFilter = "(objectCategory=computer)"
' Retrieve distinguishedName and operatingSystem attributes.
strAttributes = "distinguishedName,operatingSystem"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

' Loop through all computer objects.
Do Until objRecordSet.EOF
' Make strings lower case.
strDN = LCase(objRecordSet.Fields("distinguishedName").Value)
strOS = LCase(objRecordset.Fields("operatingsystem").Value)
' Check if computer object in cn=computers container.
If (InStr(strDN, "OU=Unassigned,OU=Computers,OU=OU,DC=york,MY=gov,DOMAIN=COM")) Then
' Check OS, skip servers.
If strOS = "windows 2000 Professional" Then
Set objMoveComputer = objW2kOU.MoveHere("LDAP://" & strDN, vbNullString)
ElseIf strOS = "Windows XP Professional" Then
Set objMoveComputer = objXPOU.MoveHere("LDAP://" & strDN, vbNullString)
End If
End If
' Move to the next computer object.
objRecordSet.MoveNext
Loop

' Clean up.
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objW2kOU = Nothing
Set objXPOU = Nothing
Start Free Trial
[+][-]05.18.2006 at 06:58AM PDT, ID: 16708863

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Tags: vbscript, objmovecomputer
Sign Up Now!
Solution Provided By: mdiglio
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.18.2006 at 10:47AM PDT, ID: 16711065

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2006 at 10:41AM PDT, ID: 16736246

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.17.2006 at 03:35PM PDT, ID: 16927927

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.21.2006 at 02:00AM PDT, ID: 16949565

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32