Hi there,

finally, I've got my script completed. Thanks to this Forum, which helped me a lot with it. Let's hear what you think about it!

The script maps printers on a printserver if the user is in a certain AD-Group (The name of the AD-Group has to be the same as the Printer-Sharename).
So far, it works great for ~130 printers and ~300 users!

Note that \\printserver has to be modified (unless your printserver is named "printserver" ;\) )
 Code:
for each $printer in SharedPrinterList("\\printserver", 1) 
	RegPrinter($printer,"\\printserver")
next 


[Domain has to be modified]
 Code:
function RegPrinter($printer,$printserver) 
	IF INGROUP("Domain\" + $printer)
		IF LocalPrinterExists ($printserver + "\" + $printer) = 0
		ADDPRINTERCONNECTION ($printserver + "\"+ $printer)
		ENDIF
	ELSE  		
		IF LocalPrinterExists ($printserver + "\" + $printer) = 1
		DELPRINTERCONNECTION ($printserver + "\" + $printer)
		ENDIF
	ENDIF
EndFunction



 Code:
function LocalPrinterExists($printer)
$LocalInstalledPrinters=EnumPrinterConnections2

	IF AScan($LocalInstalledPrinters,$printer)<>-1
		$LocalPrinterExists=1
	ELSE
		$LocalPrinterExists=0
	ENDIF
endfunction


The script requires two sub-udfs:
EnumPrinterConnections2() and
SharedPrinterList()

Furthermore I had to modify EnumPrinterConnections2, so that the printerports aren't returned


 Code:
Function EnumPrinterConnections2()
  Dim $WshNetwork, $oPrinters, $i, $PrintArray[0]
  $EnumPrinterConnections2=""
  $WshNetwork = CreateObject("WScript.Network")
  If Not @ERROR
    $oPrinters = $WshNetwork.EnumPrinterConnections
    For $i = 0 To $oPrinters.Count - 1 Step 2
      $PrintArray[Ubound($PrintArray)]=$oPrinters.Item($i+1) ; Output without Printerport, therefor excluded: +','+$oPrinters.Item($i)
      ReDim Preserve $PrintArray[Ubound($PrintArray)+1]
    Next
      If Ubound($PrintArray) > 0
        ReDIM Preserve $PrintArray[UBound($PrintArray)-1]
      Else
        $PrintArray = 0
      EndIf
  Else
    $EnumPrinterConnections2=@ERROR
    Exit $EnumPrinterConnections2
  EndIf
  $EnumPrinterConnections2=$PrintArray
EndFunction


Edited by dynadrate (2008-12-11 12:08 PM)