Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Creating multiple OU's in AD fro minput file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60221
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Creating multiple OU's in AD fro minput file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Creating multiple OU's in AD fro minput file - 5/14/2008 10:25:34 PM   
  aroberts

 

Posts: 2
Score: 0
Joined: 5/14/2008
Status: offline
Hi,
I have a problem where i need to create a whole lot of OU's in the AD, down to 4 or 5 layers, read from an input file. I am able to script to level 3, but cant work out how to get further down. This is a problem as i cant create the child objects. If someone can please help me it would be greatly appreciated. I have attached the input file and script below. The third tab is the description of the OU.

Andrew

Example input file (save as OUStructure.txt in the script location):
Root      Root      Finance      Finance Objects
Root      Finance      Users      Finance Users  
Root      Finance      Laptops      Finance Laptops
Root      Finance      Desktops      Finance Desktops
Root      Finance      Printers      Finance Printers
Root      Root      Marketing      Marketing Objects 
Root      Marketing      Users      Marketing Users   
Root      Marketing      Laptops      Marketing Laptops
Root      Marketing      Desktops      Marketing Desktops
Root      Marketing      Printers      Marketing Printers
Root      Root      Administrators      Administrators Objects
Root      Administrators      Users      Administrators Users
Root      Administrators      Laptops      Administrators Dektops
Root      Administrators      Desktops      Administrators Desktops

-----------------------------------------------------------------------------------------------------

strInputFile = "OUStructure.txt"
set objFSO = Wscript.CreateObject("scripting.filesystemobject")
Set objInputFile =  objFSO.OpenTextFile(strInputFile, 1)
Set objNetwork = WScript.CreateObject("WScript.Network")
strDomain = objNetwork.UserDomain
strRoot = "DC=" & strDomain & ",DC=local"
Do Until objInputFile.AtEndOfStream

strLine = objInputFile.readline
strLine = replace(strLine,chr(34),"")
strLine = replace(strLine,",",chr(92) & ",")

arrLine = split(strLine,vbTab)
If (arrLine(1) = "Root") then
strLDAP = "LDAP://" & strRoot
set objLDAP = getobject(strLDAP)
set objOU = objLDAP.create("organizationalUnit","OU=" & arrLine(2))
objOU.Put "Description", arrLine(3)
objOU.Setinfo

Else If (arrLine(0) = "Root") then
strLDAP = "LDAP://OU=" & arrLine (1) & "," & strRoot
set objLDAP = getobject(strLDAP)
set objOU = objLDAP.create("organizationalUnit","OU=" & arrLine(2))
objOU.Put "Description", arrLine(3)
objOU.Setinfo
Else 
strLDAP = "LDAP://OU=" & arrLine(1) & ",OU=" & arrLine(0) & "," & strRoot
set objLDAP = getobject(strLDAP)
set objOU = objLDAP.create("organizationalUnit","OU=" & arrLine(2))
objOU.Put "Description", arrLine(3)
objOU.Setinfo
End If
End If

Loop
wscript.echo "Complete"

< Message edited by aroberts -- 5/15/2008 12:25:45 AM >
 
 
Post #: 1
 
 RE: Creating multiple OU's in AD fro minput file - 5/15/2008 3:43:18 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
What if the OU you're trying to create already exists? Are you checking for those?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aroberts)
 
 
Post #: 2
 
 RE: Creating multiple OU's in AD fro minput file - 5/15/2008 3:58:43 PM   
  aroberts

 

Posts: 2
Score: 0
Joined: 5/14/2008
Status: offline
I would like to be able to check if it already exists, but im not really sure how to do it. I guess thats an additional problem along with creating OUs four deep.

(in reply to aroberts)
 
 
Post #: 3
 
 RE: Creating multiple OU's in AD fro minput file - 5/16/2008 2:18:33 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
This may help the search for an OU to see if it exists before you try creating it
http://www.microsoft.com/technet/scriptcenter/scripts/ad/search/ous/default.mspx

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aroberts)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Creating multiple OU's in AD fro minput file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts