Page 1 of 1 1
Topic Options
#147616 - 2005-09-12 06:34 PM Create Active Directory Printer group if none exists
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
I used this script to create groups for each printer in Active Directory. I now use these groups to install and map default and additional printers for workstations.

Each time I add a printer in Active Directory, I manually create the corresponding groups now. I'd like to be able to execute this script each time I create a printer and have it try to create the printer group ONLY if none exists already.

How do I modify this script to check for the existence of the group first and exit if one exists or continue if none exists.

Thank you for any assistance.

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.txt
$printers = GetObject("LDAP://OU=Printers,DC=company,DC=local")
$DN_of_OU ="OU=Printer Groups,DC=company,DC=local"

if @error
? @error - @serror
else

$rc=redirectoutput($logfile,1)

for each $printer in $printers
$printername = $printer.name
$printername = substr($printername,4)

if left($printername,7) = "SRV-01-"

$printername = lcase(substr($printername,8)) ;? "Printername is "$printername

$defprintgroup = "D01_"+$printername ;? "Default printer group is "$defprintgroup


if CreateAdGroup($DN_of_OU, $defprintgroup, "global", 1, "Default Printer Group")
? "Group " + $defprintgroup + " successfully created"
else
? "CreateAdGroup " + $defprintgroup + " Failed with Error: " + @error
endif

$addlprintgroup = "A01_"+$printername ;? "Additional printer group is "$addlprintgroup

if CreateAdGroup($DN_of_OU, $addlprintgroup, "global", 1, "Additional Printer Group")
? "Group " + $addlprintgroup + " successfully created"
else
? "CreateAdGroup " + $addlprintgroup + " Failed with Error: " + @error
endif

endif

next

$rc=redirectoutput('')

endif


Top
#147617 - 2005-09-14 05:46 PM Re: Create Active Directory Printer group if none exists
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
No interest in this one?
Top
#147618 - 2005-09-18 07:25 PM Re: Create Active Directory Printer group if none exists
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You already gave the answer yourself. Check if the group exists.
Code:

$group = getobject("WinNT://$target/$group")
if vartype($group) <> 9
; create group
endif


Just fill in $target and $group as appropriate.
_________________________
There are two types of vessels, submarines and targets.

Top
#147619 - 2005-09-29 06:47 PM Re: Create Active Directory Printer group if none exists
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Thanks.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org