All of my printers are named similarly, q-printer. I created group names based on printer name. 2 groups exist for each printer. D01_q-printer A01_q-printer. I created an AD group and put the COMPUTERS in the group. I use ComputerInGroup.udf to see if the computer is a member and then add printers and set as default based on printer group name. I have many printers, so it was well worth the amount of time to figure out this script. And not everyone gets printers assigned by a script. So first I put the computers in the Printer Setup Group, and if they are here, I call the printers.kix. Printers.kix looks at the groups created for each printer. If you don't have many printers and all users run the script, you can use a simpler script.
Create an AD Group for each printer.
Code:
If ComputerInGroup("abc")
AddPrinterConnection ("\\server\printer name 1")
EndIf
If ComputerInGroup("def")
AddPrinterConnection ("\\server\printer name 2")
EndIf
;============ ComputerInGroup Function ===========
;Function ComputerInGroup()
;
;Author Radimus (really Howard Bullock's code)
;
;Contributors Almost entirely written by Howard Bullock
; I just stuffed it into UDF format and posted it
;
;Action Returns a 1 if the @wksta is a member of domain group
;
;Syntax ComputerInGroup($group,optional $Domain)
;
;Version 1.00
;
;Date 2003-Sep-03
;
;Date Revised
;
;Revision Reason 1.00
;
;Parameters $group = name of group to test for
; $domain = optional parameter for testing a different domain than current
;
;Remarks see Ingroup(), but for computer accounts instead of user accounts
;
;Returns 1 if in specified group
; 0 if not
; @error =1 for bad group or domain
;
;Dependencies ADSI
;
;KiXtart Ver Written and tested with KiXtart v4.21
;
;Example If ComputerInGroup('domain computers')=1
; ? 'Computer is a member'
; endif
Function ComputerInGroup($group,optional $Domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif
if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction