Break on
;Gets all currently installed printers.
$printers = EnumPrinterConnections2()
;Get the current default printer.
$defaultprinter = GetDefaultPrinter()
;Put the name of the old server in a variable.
$oldserver = "oldservername"
;Put the name of the new server in a variable.
$newserver = "newservername"
;This For - Each loop does the actions between the For and Next
;lines for all installed printers gathered above.
For Each $printer in $printers
;If the name of the old server is found in the name of the currently
;installed printer do the actions below.
If InStr($printer, $oldserver)
;Delete the old printer.
$rc = DelPrinterConnection($printer)
;Split the old printer name on the name of the old server.
$newprinter = Split($printer, $oldserver)
;Join the old printer name with the name of the new server
;and put the outcome in the $newprinter variable.
$newprinter = Join( $newprinter, $newserver ")
;Install the new printer.
$rc = AddPrinterConnection($newprinter)
;If the old printer deleted above was the default printer
;then set the new printer as default.
;If not then skip this part and move on the next printer.
If $printer = $defaultprinter
$rc = SetDefaultPrinter($newprinter)
EndIf
EndIf
Next