PC Review


Reply
Thread Tools Rate Thread

Adding multiple OU's in AD tree.

 
 
jekar2.0@gmail.com
Guest
Posts: n/a
 
      31st Jan 2007
I work for a county school system and have been asked to go through
our AD domain and find all containers labeled "computer", and add
three sub containers underneath. ( Administration, teacher, student.)
This is a rather large task being that there are roughly sixty school
containers, and nearly one hundred departments, each having a
"computers" OU.

My question is this. Is there a script that I could modify, or an app
that would automate the process? I am not great with scripting, but
can take a decent example and modify to fit my needs if one exists.

Thank you in advance for your help,
Gary

 
Reply With Quote
 
 
 
 
Evan
Guest
Posts: n/a
 
      31st Jan 2007
"Computers" is a container
You can't add OU's to a container
the computers should be moved
to the appropriate OU's that contain
the group policy that you want applied to the computer object.

I suggest whoever told you to add containers to the computer
container should learn more about planning an AD structure first

- Evan

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I work for a county school system and have been asked to go through
> our AD domain and find all containers labeled "computer", and add
> three sub containers underneath. ( Administration, teacher, student.)
> This is a rather large task being that there are roughly sixty school
> containers, and nearly one hundred departments, each having a
> "computers" OU.
>
> My question is this. Is there a script that I could modify, or an app
> that would automate the process? I am not great with scripting, but
> can take a decent example and modify to fit my needs if one exists.
>
> Thank you in advance for your help,
> Gary
>



 
Reply With Quote
 
jekar2.0@gmail.com
Guest
Posts: n/a
 
      1st Feb 2007
On Jan 31, 1:48 pm, "Evan" <e...@hotmail.com> wrote:
> "Computers" is a container
> You can't add OU's to a container
> the computers should be moved
> to the appropriate OU's that contain
> the group policy that you want applied to the computer object.
>
> I suggest whoever told you to add containers to the computer
> container should learn more about planning an AD structure first
>
> - Evan
>
> <jekar...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >I work for a county school system and have been asked to go through
> > our AD domain and find all containers labeled "computer", and add
> > three sub containers underneath. ( Administration, teacher, student.)
> > This is a rather large task being that there are roughly sixty school
> > containers, and nearly one hundred departments, each having a
> > "computers" OU.

>
> > My question is this. Is there a script that I could modify, or an app
> > that would automate the process? I am not great with scripting, but
> > can take a decent example and modify to fit my needs if one exists.

>
> > Thank you in advance for your help,
> > Gary


Thanks even, but I belive we may not have been on the same page. The
"computer" ou is a child ou, under a school or department ou.
I have received a solution that worked well and wanted to post, in
case anyone might find it helpful.

First, I assume your containers are all Organizational Units. Perhaps
the
most efficient way to find all OU's called ou=Computer is to use ADO.
We
search for all objects with objectCategory=organizationalUnit and
ou=Computer. We need to bind to each, so we retrieve the Distinguished
Name.
We use the Create method of the container/OU object to create child
OU's
called Administration, Teacher, and Student. My solution:
===========
Option Explicit

Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strDN, objOU, objNewOU

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

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on all Organizational Units with Relative Distinguished
' Name ou=Computer.
strFilter = "(&(objectCategory=organizationalUnit)(ou=computer))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName"

' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes &
";subtree"

' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strDN = adoRecordset.Fields("distinguishedName").Value
' Bind to object.
Set objOU = GetObject("LDAP://" & strDN)
' Create child OU's.
' Trap error if OU already exists.
On Error Resume Next
Set objNewOU = objOU.Create("organizationalUnit",
"ou=Administration")
If (Err.Number <> 0) Then
Err.Clear
Wscript.Echo strDN & " already has child OU Administration"
Else
objNewOU.SetInfo
End If
Set objNewOU = objOU.Create("organizationalUnit", "ou=Teacher")
If (Err.Number <> 0) Then
Err.Clear
Wscript.Echo strDN & " already has child OU Teacher"
Else
objNewOU.SetInfo
End If
Set objNewOU = objOU.Create("organizationalUnit", "ou=Student")
If (Err.Number <> 0) Then
Err.Clear
Wscript.Echo strDN & " already has child OU Student"
Else
objNewOU.SetInfo
End If
On Error GoTo 0
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close

' Clean up.
Set objRootDSE = Nothing
Set adoCommand = Nothing
Set adoConnection = Nothing
Set adoRecordset = Nothing
========
Next problem is probably how to move existing computer objects into
the
correct OU. Is there some way to tell, perhaps from the NetBIOS name,
which
OU is proper? To move, you would bind to the new container/OU object
and use
the MoveHere method. You pass the AdsPath of the object to this
method.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding another table to Tree View JJ297 Microsoft ASP .NET 0 28th Aug 2007 07:39 PM
Help on Adding tree node ?? =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= Microsoft Dot NET 1 13th May 2005 04:30 PM
adding subnodes to a tree recursively =?Utf-8?B?RGFuIE5hc2g=?= Microsoft ASP .NET 10 18th Oct 2004 01:29 AM
Adding designer support to a custom tree control =?Utf-8?B?SmFtZXMgR2V1cnRz?= Microsoft C# .NET 9 13th Feb 2004 01:16 AM
Adding a NT4 Domain to my Tree while upgrading Marty Amaral Microsoft Windows 2000 Active Directory 0 4th Nov 2003 08:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:50 AM.