Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I dynamically pass the OU or any argumnet to my script? 2

Status
Not open for further replies.

fpachon

MIS
Feb 9, 2006
22
US
I have a script that creates groups. I need to bind these groups to different OUs under different levels in the tree.

How can my script pass the OU dynamically to this line

Code:
Set objOU = GetObject("LDAP://ou=FH2,dc=dylan,dc=local")

Currently I have hard coded the OU where I want to create the group in, but this is not flexible enough. I will pass the OU from the same csv file that I am reading the groups from.

Any help would be appreciated.

Thanks.
 
strOU = "FH2"
Set objOU = GetObject("LDAP://ou=" & strOU & ",dc=dylan,dc=local")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
where is your code for creating the groups in a specific OU?? perhaps we can work on this together as i will need to do something exactly as you describe tomorrow....
 
Below is my code. This is only my 10th script I wrote. I am new to this. This code lacks error checking.


' Input File: GroupList.csv
'
' Parameters: group,samaccountname,description,organizationalunit
'

Dim objFSO, objTextfile, group_arr, s

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextfile = objFSO.OpenTextFile("GroupList.csv", ForReading)

Do while objTextfile.AtEndOfStream <> True

s = objTextfile.Readline

If instr(s, ",") Then

group_arr = split(s, ",")

wscript.Echo "group = " & group_arr(0)
wscript.Echo "sam account name = " & group_arr(1)
wscript.Echo "description = " & group_arr(2)
wscript.Echo "OU = " & group_arr(3)

Set objOU = GetObject("LDAP://ou=" & group_arr(3) & ",dc=test")

Set objGroup = objOU.Create("group", "cn=" & group_arr(0))

objGroup.Put "sAMAccountName", ""& group_arr(1)
objGroup.Put "description", "" & group_arr(2)
objGroup.SetInfo

Else

Wscript.Echo "End of file"

End If

Loop

objTextFile.Close


 
Thank you EBGreen. I modified my code using your suggestions and added my array to substitute your string.

Thanks.
 
thanks for posting your code fpachon, it will come in very useful for me tomorrow, i will mention you as a contributor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top