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