Choose your language

Choose your login

Contact us

Automatically set up the PaperCut TCP/IP Port

THE PAGE APPLIES TO:

“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.

Preparation

Before making changes to your environment using PowerShell we strongly recommend that you take a backup of your Windows Print server. Thankfully there’s an easy way to do this using Print Management Console.

Configure all printers to use the PaperCut TCP/IP Port

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

This script will get all of the locally installed printers on your server, and then for each printer configured to use a Standard TCP/IP Port it will look at the IP address in the printer name and create a new PaperCut Port based on that.

Here are a few things to keep in mind:

  • This script will only apply to print queues that have a Standard TCP/IP Port, so WSD ports and special ports (like COM1, LPT1, or nul) will be ignored.
  • This script will edit the registry to create the PaperCut Port for each printer as needed.
  • This script uses PowerShell commands that were introduced with Windows Server 2012, so it will not work on Windows 2008 R2 or older versions.
  • WARNING: This assumes that your Standard TCP/IP Ports are named correctly with the right IP address for each printer. If this is not the case, there may be unexpected results.
#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.

This script will get all of the locally installed printers on your server that have “PaperCut TCP/IP Port” in the name and then will create a new Standard TCP/IP Port based on that.

Here are a few things to keep in mind:

  • This script will only apply to print queues that use the PaperCut TCP/IP Port, and assumes that these ports are named correctly with the right IP address for each printer.
  • This script will create each port with a SNMP enabled and a community string of “public” as this is the default for most environments. If your printers are configured to use a different SNMP Community String, please replace “public” with the correct name or Windows may report that the printer is offline.
  • This script uses PowerShell commands that were introduced with Windows Server 2012, so it will not work on Windows 2008 R2 or older versions.
#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: How-to Articles , Print Queues


Comments

Last updated February 15, 2024