Automatically set up the PaperCut TCP/IP Port

KB Home   |   Automatically set up the PaperCut TCP/IP Port

“Help! Iím a sysadmin or PaperCut partner trying to configure all the print queues on a Windows server to use the PaperCut TCP/IP port. Is there a way to script this setup automatically?”

A word about using the PaperCut TCP/IP Port…

PaperCutís Hardware Page Count Validation ensures that PaperCut is able to determine the exact number of pages printed by a device for each job. As a prerequisite for using this feature, a printer must be configured to use the PaperCut TCP/IP Port. Because it can be a bit tedious to go through every single printer on a server weíve put together a couple scripts to automatically configure every printer to use the PaperCut TCP/IP Port (and switch back to using Standard TCP/IP Ports if needed).

Note that this should come with a word of caution. Using the PaperCut TCP/IP Port is not recommended in all scenarios. It’s best used when you need PaperCut to check the printerís page meter to confirm the total number of printed pages. By necessity this feature will slow down printing so that the PaperCut server can track the number of pages printed by each printer. For this reason, we recommend using a Standard TCP/IP Port in most cases. Have a look at this article for the rest of our advice on configuring Windows print queues.

Configure all printers to use the PaperCut TCP/IP Port

Run the following script in an elevated PowerShell window on your print server.

#SWITCH ALL PRINTERS FROM STANDARD TCP/IP PORTS TO PAPERCUT TCP/IP PORTS
$printers = Get-Printer
foreach ($printer in $printers) {
    $printerport = Get-PrinterPort -Name $printer.PortName
        if ($printerport.Description -eq "Standard TCP/IP Port") {
            $newport = $printer.PortName.Insert(0,"PAPERCUT_")
                Write-Host "Adding keys to the registry for" $newport
                REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\PaperCut TCP/IP Port\Ports\$newport" /v HostName /t REG_SZ /d $printerPort.Name /f
                REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\PaperCut TCP/IP Port\Ports\$newport" /v PortNumber /t REG_DWORD /d 0x0000238c /f
        }
}
Write-Host "Restarting the Print Spooler Service"
Restart-Service -Name Spooler -Force
foreach ($printer in $printers) {
    $printerport = Get-PrinterPort -Name $printer.PortName
        if ($printerport.Description -eq "Standard TCP/IP Port") {
            $newport = $printer.PortName.Insert(0,"PAPERCUT_") 
            Write-Host "Changing" $printer.name "from port" $printer.PortName "to" $newport
            Set-Printer $printer.name -PortName $newport
        }
}

Revert from PaperCut TCP/IP Ports to Standard TCP/IP Ports

Run the following script in an elevated PowerShell window on your print server.

#SWITCH ALL PRINTERS FROM PAPERCUT TCP/IP PORTS TO STANDARD TCP/IP PORTS
$printers = Get-Printer
foreach ($printer in $printers){
    $printerport = Get-PrinterPort -Name $printer.PortName
        if ($printerport.Description -eq "PaperCut TCP/IP Port") {
            $newport = $printer.PortName.Trim("PAPERCUT_")
            Write-Host "Adding Standard TCP/IP Port" $newport "to replace PaperCut TCP/IP Port" $printer.PortName
            Add-PrinterPort $newport -PrinterHostAddress $newport -PortNumber 9100 -SNMP 1 -SNMPCommunity public
        }
}
Write-Host "Restarting the Print Spooler Service"
Restart-Service -Name Spooler -Force
foreach ($printer in $printers) {
    $printerport = Get-PrinterPort -Name $printer.PortName
        if ($printerport.Description -eq "PaperCut TCP/IP Port") {
            $newport = $printer.PortName.Trim("PAPERCUT_")
            Write-Host "Changing" $printer.name "from port" $printer.PortName "to" $newport
            Set-Printer $printer.name -PortName $newport
        }
}

Still have questions?

Let us know! We love chatting about whatís going on under the hood. Feel free to leave a comment below or visit our Support Portal for further assistance.


Categories: Hardware Checking

Comments

Share your findings and experience with other PaperCut users. Feel free to add comments and suggestions about this Knowledge Base article. Please don't use this for support requests.

Article last modified on July 27, 2018, at 09:30 PM
Printable View   |   Article History   |   Edit Article