I'm utilizing a script I found by Bob Kelly to take existing network mapped printers, delete them & then re-create them pointing via the new server as I'm trying to decommission the old server within the next few days.

Although the script is working beautifully, I've got to deploy this into our main Kix script which will deploy to over a 100 users, & I need to have the script first look up & see what the current default printer is, & then when all is said & done & the new printers are in place I need whatever the new version of the old printer is to be set automatically as default.

I've migrated the printers from old server to new using export/import in print management, so literally the only thing that is changing is the server name.

The script I'm using which needs to be modified a to add in the defaults is as follows:

 Code:
$NewServer="\\NEW-SERVER\"
$OldServer="\\OLD-SERVER\"
$Cnt=0
$SubKey= "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Printerports"
$PrintName=EnumValue ($SubKey, $Cnt)
While $PrintName <> ""
       If Left($PrintName, Len($OldServer))=$OldServer
               $NewPrintName=$NewServer + SubStr($PrintName,Len($OldServer) + 1,Len($PrintName))
        ? "Deleting; " $PrintName "..."
        $= DelPrinterConnection("$PrintName")
        ? @SERROR
        ? "Connecting; " $NewPrintName "..."
        $= AddPrinterConnection("$NewPrintName")
        ? @SERROR
Else
        $Cnt= $Cnt + 1
Endif
$PrintName=EnumValue ($Subkey, $Cnt)

Loop


END OF CODE:

Like I said, the code works awesome but when it runs it kind of randomly decides on a printer to set as default, & considering that out of the 100+ workstations there are 150+ users that all point in random directions to their default printers that's why I want to fix this using KIX as we are using it for login scripting anyway & if it's just a matter of adding a few extra lines of code that would sure make my life a lot easier.

Thoughts?

Thanks in advance everyone.


Edited by Mart (2020-07-03 09:21 AM)
Edit Reason: Please use code tags when posting code.