#46675 - 2003-10-14 06:01 PM
Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
I would like to query an OU for objects and create security groups.
OU=Printers
The objects are printers that are published in AD. I would like to create two groups for each printer, one for default printer, one for additional printer.
Printer object names: MRH-01-q-mis
Group names to be created:
DefPrinter_mrh-01_q-mis AddlPrinter_mrh-01_q-mis
I found a CreateADGroup by Howard, but am unsure of how to query the Printers OU and enumerate the objects and create a script that I can use with CreateADGroup to add the groups for the printers.
I used this syntax to obtain computer group membership for the purpose of adding printers based upon group membership. I'd like to now create the groups for the corresponding printers, checking for the existence of each group BEFORE creating them.
code:
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$") if @error ? @serror else for each $grp In $WS.Groups $GrpName = $grp.Name
if left($GrpName,11) = "DefPrinter_" $defprinter = substr($GrpName,12) $defprinter = join(split($defprinter,"_"),"\")
No idea what I'm doing, but going to start here:
code:
$logfile=c:\printers.xls
$printers = GetObject("LDAP://CN=Printers,DC=test,DC=local)
if @error ?@serror else
$rc=redirectoutput($logfile,1)
for each $printer in $printers $printername = $printer.name $printername = substr ($printername,4) ? $printername ; to see results for now if left($printername,7) = "MRH-01-" $printgroup = substr($printerpName,8) ; create groups with createadgroup.udf ; work to do on this next $rc=redirectoutput('')
endif
Any direction is appreciated.
tjcarst [ 14. October 2003, 19:42: Message edited by: tjcarst ]
|
Top
|
|
|
|
#46677 - 2003-10-14 07:28 PM
Re: Create AD Global Groups for printer objects
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Checkout this thread and related links. It will give you a way to enumerate objects.
then for each printer object, get the name and call my CreateADgroup() two times, once for each group to create.
|
Top
|
|
|
|
#46678 - 2003-10-14 07:40 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Thanks, I'll get started on that.
|
Top
|
|
|
|
#46679 - 2003-10-14 07:55 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Okay, using this code, I am able to get the printer names from the Printers OU and trim off the CN=. I just need to now create the variables for the new groups I want to create using CreateADGroup.udf
code:
;********** Beginning of group creation ********* $logfile=c:\printers.xls $printers = GetObject("LDAP://OU=Printers,DC=madonna,DC=local")
if @error ? @serror else
$rc=redirectoutput($logfile,1)
for each $printer in $printers $printername = $printer.name $printername = substr($printername,4)
if left($printername,7) = "MRH-01-" $printgroup = substr($printername,8) ? $printgroup ; write output to file for now endif
next
$rc=redirectoutput('')
endif
[ 14. October 2003, 19:56: Message edited by: tjcarst ]
|
Top
|
|
|
|
#46681 - 2003-10-14 08:21 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
This is what I have now. I had to strip off the leading server portion and add back in for the group names in order to match the syntax of my script that I am using. The printers in AD are preceded by the server name with a dash and not an underscore and the server is in uppercase. MRH-01-q-mis not mrh-01_q-mis.
code:
;********** Beginning of group creation ********* call @ScriptDir+'\CreateAdGroup.udf'
$printers = GetObject("LDAP://OU=Printers,DC=test,DC=local")
if @error ? @serror else
for each $printer in $printers $printername = $printer.name $printername = substr($printername,4)
if left($printername,7) = "MRH-01-"
$printername = lcase(substr($printername,8)) $defprintgroup="DefPrinter_mrh-01_"+$printername $rc=CreateADGroup($defprintgroup)
$addlprintgroup="AddlPrinter_mrh-01_"+$printername $rc=CreateADGroup($addlprintgroup)
endif
next
endif
[ 14. October 2003, 20:26: Message edited by: tjcarst ]
|
Top
|
|
|
|
#46682 - 2003-10-14 08:29 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
I also need to specify the Printer Groups OU for the creation.
|
Top
|
|
|
|
#46683 - 2003-10-14 08:37 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Okay, I think this should work. Thanks for your great assistance!!
About 200 groups will be created when I hit enter. I'd better test just a bit more....
code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920
call @ScriptDir+'\CreateAdGroup.udf'
;********** Beginning of group creation ********* $printers = GetObject("LDAP://OU=Printers,DC=test,DC=local")
if @error ? @serror else
for each $printer in $printers $printername = $printer.name $printername = substr($printername,4)
if left($printername,7) = "MRH-01-" $printername = lcase(substr($printername,8))
$defprintgroup = "DefPrinter_mrh-01_"+$printername $DN_ofOU ="OU=Printer Groups,DC=test,DC=local" $rc=CreateAdGroup($DN_of_OU, $defprintgroup, "global", 0, "Default Printer")
$addlprintgroup = "AddlPrinter_mrh-01_"+$printername $rc=CreateAdGroup($DN_of_OU, $addlprintgroup, "global", 0, "Additional Printer")
? $defprintgroup ; write output to file for now endif
next
endif
[ 14. October 2003, 20:39: Message edited by: tjcarst ]
|
Top
|
|
|
|
#46684 - 2003-10-14 08:57 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
I receive an error when running my script with the CreateAdGroup.udf.
ERROR : unknown command [Then]! Script: CreateAdGroup.udf Line : 74
|
Top
|
|
|
|
#46685 - 2003-10-14 09:43 PM
Re: Create AD Global Groups for printer objects
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Crap!!!
Don't know how that got in there. Delete the word "Then" on line 74 or 75 of the UDF. Sorry. I will clean up the UDF post on Korg.
I know this was tested by Doc and myself.
|
Top
|
|
|
|
#46686 - 2003-10-14 10:12 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Thanks!
|
Top
|
|
|
|
#46687 - 2003-10-14 10:16 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Okay - now I get
CreateAdGroup Failed with Error: -2147352567
code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920
call @ScriptDir+'\CreateAdGroup.udf'
;********** Beginning of group creation *********
$logfile=c:\printers.xls $printers = GetObject("LDAP://OU=Printers,DC=test,DC=local") $DN_of_OU ="OU=Printer Groups,DC=test,DC=local"
if @error ? @serror else
$rc=redirectoutput($logfile,1)
for each $printer in $printers $printername = $printer.name $printername = substr($printername,4)
if left($printername,7) = "MRH-01-"
$printername = lcase(substr($printername,8))
$defprintgroup = "D_mrh-01_"+$printername
if CreateAdGroup($DN_of_OU, $defprintgroup, "global", 1, "Default Printer") ? "Group successfully created" else ? "CreateAdGroup Failed with Error: " + @error endif
$addlprintgroup = "A_mrh-01_"+$printername
? $addlprintgroup if CreateAdGroup($DN_of_OU, $addlprintgroup, "global", 1, "Additional Printer") ? "Group successfully created" else ? "CreateAdGroup Failed with Error: " + @error endif
endif
next
$rc=redirectoutput('')
endif
[ 14. October 2003, 22:38: Message edited by: tjcarst ]
|
Top
|
|
|
|
#46688 - 2003-10-15 12:42 AM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Well, searchign the boards for that error yielded a few hits. However, I am still unable to fix.
I'll work on this tomorrow.
I also noted that the printers I've created with a script I found here using AddDefaultPrinter and SetDefaultPrinter are not recognized by Acrobat Reader. So, it looks like I'm further from my solution than I thought.
I can say this is fun to troubleshoot. I must be a crazy person
tjcarst
|
Top
|
|
|
|
#46689 - 2003-10-15 05:00 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
Well, today Acrobat sees the printers. Nothing changed on XP machine, I didn't even logout. Another mystery. Oh, well, they are working. Still haven't figured out the error when running script to create the groups in AD, though....
|
Top
|
|
|
|
#46690 - 2003-10-16 08:28 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
I think there is a problem with creating the groups from the script due to the way they are created using for each $printer in $printers.
I can get the script to return the correct name of the group I want to create for $defprinter, but I cannot create multiple computer groups based upon the printer names.
Using CreateADGroup.udf, I can create a script that creates one group successfully, just not the whole listing retrieved by 'for each'
Somehow I need to store the results of the printer names and then create the group names based on my variables. To a text or ini file? How do I modify the script to do this?
|
Top
|
|
|
|
#46691 - 2003-10-16 08:55 PM
Re: Create AD Global Groups for printer objects
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I do not understand what your problem actually is. If you are referring to my CreateADGroup() udf, it should be quite capable of creating a group with each call to it.
Could you please post the KiXtart code you are using to loop through you name and call createADGroup()? [ 16. October 2003, 20:55: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#46692 - 2003-10-17 06:09 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
If I disable the portion that creates the groups, I can see that I am retrieving the printer names and generating the correct group name I want to create.
If I enable the portion that creates the groups, I get the error after every group: A_mrh-01_q-therapy CreateAdGroup Failed with Error: -2147352567 A-mrh-01_q-therapy2 CreateAdGroup Failed with Error: -2147352567
However, if I don't generate the group names using my script and just type into the script the name of the group I want to create, it is successfully created.
I don't think I am correctly passing the group names to CreateAdGroup in my script and am not clever enough to figure out what needs to be changed.
Thanks for any direction you can give.
tjcarst
code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920
call @ScriptDir+'\CreateAdGroup.udf'
;********** Beginning of group creation *********
$logfile=c:\printers.xls $printers = GetObject("LDAP://OU=Printers,DC=madonna,DC=local") $DN_of_OU ="OU=Printer Groups,DC=madonna,DC=local" if @error ? @serror else $rc=redirectoutput($logfile,1) for each $printer in $printers $printername = $printer.name $printername = substr($printername,4) if left($printername,7) = "MRH-01-" $printername = lcase(substr($printername,8)) $defprintgroup = "D_mrh-01_"+$printername $addlprintgroup = "A_mrh-01_"+$printername if CreateAdGroup($DN_of_OU, $defprintgroup, "global", 1, "Default Printer") ? "Group successfully created" else ? "CreateAdGroup Failed with Error: " + @error endif if CreateAdGroup($DN_of_OU, $addlprintgroup, "global", 0, "Additional Printer") ? "Group successfully created" else ? "CreateAdGroup Failed with Error: " + @error endif endif next $rc=redirectoutput('') endif
[ 17. October 2003, 18:29: Message edited by: tjcarst ]
|
Top
|
|
|
|
#46693 - 2003-10-17 06:46 PM
Re: Create AD Global Groups for printer objects
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The only suggestion I can offer is to add additional debugging code into the CreateADGroups udf.
Add Cerror() udf to your script.
Output the variables values enclosed in quotes or other delimiter so that you can see where the value starts and stops. This is incase you have spaces or other characters that would be not seen.
Output the values and results for each ADSI call, get, put, and setinfo line.
Please give some more info regarding your test where if you supply the text name the function works and in the script the function fails. This would lead me to belive that you are passing the function invalid data even though it may look correct.
|
Top
|
|
|
|
#46694 - 2003-10-17 07:09 PM
Re: Create AD Global Groups for printer objects
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
This successfully creates the D_mrh-01_q-therapy print group in AD.
And I can see when I run the other part of the script without the CreateADGroup function, that the group names are returned correctly to screen or file as specified.
code:
call @ScriptDir+'\CreateAdGroup.udf'
;********** Beginning of group creation *********
$logfile=c:\printers.xls $printers = GetObject("LDAP://OU=Printers,DC=madonna,DC=local") $DN_of_OU ="OU=Printer Groups,DC=madonna,DC=local" if @error ? @serror else $rc=redirectoutput($logfile,1) for each $printer in $printers $printername = $printer.name $printername = substr($printername,4) if left($printername,7) = "MRH-01-" $printername = lcase(substr($printername,8)) $defprintgroup = "D_mrh-01_"+$printername ; if CreateAdGroup($DN_of_OU, $defprintgroup, "global", 1, "Default Printer") ; ? "Group successfully created" ; else ; ? "CreateAdGroup Failed with Error: " + @error ; endif ; $addlprintgroup = "A_mrh-01_"+$printername if CreateAdGroup($DN_of_OU, "D_mrh-01_q-therapy", "global", 1, "Additional Printer") ? "Group successfully created" else ? "CreateAdGroup Failed with Error: " + @error endif endif next $rc=redirectoutput('') endif
[ 18. October 2003, 20:04: Message edited by: tjcarst ]
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|