How to Add TCP Printer Ports and Printers in Bulk Using PowerShell

Struggling to add network printers to a print server or laptop? The GUI can be clunky and inefficient, especially when dealing with multiple devices. Fortunately, PowerShell offers a fast, efficient, and scalable way to handle this task—saving you time and headaches. Whether you’re managing one printer or dozens, this guide will walk you through adding TCP printer ports and printers with PowerShell. And demonstrate how you can add them in bulk using a CSV file.

Add a printer TCP port using powershell

The syntax for adding the TCP print port via PowerShell is as follows:

Add-PrinterPort -Name "ip_IPAddress" -PrinterHostAddress IPAddress

Examples

Here is an example of the command with example data. This assumes your printer has an IP address of 10.0.0.7:

Add-PrinterPort -Name "ip_10.0.0.7" -PrinterHostAddress 10.0.0.7

Bulk-add printer ports

As you can see in the section above, the process is pretty easy. You could easily read from a CSV file, and then loop through the contents using the above example.

For example, here is a PowerShell script that will read in a CSV, then create printer ports for each entry in the csv file:

# Import the CSV file containing a list of printer IPs (CSV should have a column 'ip')
$printerportlist = Import-Csv C:\printerportlist.csv

# Loop through each row in the CSV file
Foreach ($port in $printerportlist) {
    # Set a name variable for the printer port
    $name = "ip_" + $port.ip

    # Create the printer port
    Add-PrinterPort -Name $name -PrinterHostAddress $port.ip
}

The above script should work as long as your printerporlist.csv has a column header called ip

Here is an example of what the CSV file might look like:

PrinterNameIPDriverName
OfficePrinter110.0.0.7HP Universal Printing PCL 6
OfficePrinter210.0.0.8HP Universal Printing PCL 6

Adding a printer using PowerShell

Once you have created the TCP printer port, you can use the Add-Printer cmdlet in PowerShell to create a printer and associate it with the TCP port.

Before running the Add-Printer command, ensure the driver is installed on the print server. You can check this using the Get-PrinterDriver cmdlet. If the driver isn’t listed, you’ll need to install it manually or via PowerShell with the Install-PrinterDriver cmdlet.

Here’s how you can add a printer:

Add-Printer -Name "PrinterName" -DriverName "Printer Driver Name" -PortName "PortName"

-Name: The name you want to assign to the printer (e.g., “Office Printer”).

-DriverName: The exact name of the printer driver installed on the print server. You can check installed drivers using the Get-PrinterDriver cmdlet.

-PortName: The name of the TCP port you created (e.g., “IP_10.0.0.7”).

Example

Example:

If you previously created a TCP port named IP_10.0.0.7 and have a driver called HP Universal Printing PCL 6, the command would look like this:

Add-Printer -Name "Office Printer" -DriverName "HP Universal Printing PCL 6" -PortName "IP_10.0.0.7"

Bulk add printers and TCP ports using PowerShell

Here’s an example PowerShell script to add multiple printers in bulk using a CSV file and a loop. The script assumes the CSV file contains the necessary information for each printer, such as the printer name, IP address, and driver name.

# Import the CSV file containing printer details
$printerList = Import-Csv -Path "C:\printers.csv"

# Loop through each printer in the CSV file
foreach ($printer in $printerList) {
    # Set the port name based on the IP address
    $portName = "IP_" + $printer.IP

    # Create the TCP/IP port for the printer
    Write-Host "Creating TCP Port for $($printer.PrinterName) at $($printer.IPAddress)"
    Add-PrinterPort -Name $portName -PrinterHostAddress $printer.IPAddress

    # Add the printer and associate it with the port and driver
    Write-Host "Adding printer $($printer.PrinterName)"
    Add-Printer -Name $printer.PrinterName -DriverName $printer.DriverName -PortName $portName
}

Write-Host "Printers have been added successfully!"

Here’s an example PowerShell script to add multiple printers in bulk using a CSV file and a loop. The script assumes the CSV file contains the necessary information for each printer, such as the printer name, IP address, and driver name.

Example CSV File

Save this as printers.csv:

PrinterNameIPAddressDriverName
OfficePrinter110.0.0.7HP Universal Printing PCL 6
OfficePrinter210.0.0.8Canon Generic Printer
OfficePrinter310.0.0.9Brother HL-2270DW Series

PowerShell Script

powershellCopy code# Import the CSV file containing printer details
$printerList = Import-Csv -Path "C:\printers.csv"

# Loop through each printer in the CSV file
foreach ($printer in $printerList) {
    # Set the port name based on the IP address
    $portName = "IP_" + $printer.IPAddress

    # Create the TCP/IP port for the printer
    Write-Host "Creating TCP Port for $($printer.PrinterName) at $($printer.IPAddress)"
    Add-PrinterPort -Name $portName -PrinterHostAddress $printer.IPAddress

    # Add the printer and associate it with the port and driver
    Write-Host "Adding printer $($printer.PrinterName)"
    Add-Printer -Name $printer.PrinterName -DriverName $printer.DriverName -PortName $portName
}

Write-Host "Printers have been added successfully!"

Script Breakdown

  1. Import the CSV File: The Import-Csv cmdlet reads the printers.csv file, creating objects for each row where columns like PrinterName, IPAddress, and DriverName become properties.
  2. Loop Through the CSV Rows: For each printer in the list:
    • A TCP/IP port is created using the Add-PrinterPort cmdlet.
    • The printer is added with the Add-Printer cmdlet, associating it with the specified port and driver.
  3. Logging with Write-Host: Provides status updates for each printer during execution.

Notes:

  • Ensure the driver name in the CSV matches the installed drivers on your print server. Use Get-PrinterDriver to list all available drivers.
  • If you encounter permissions issues, run the script as an administrator.
  • Adjust the file path for the CSV (C:\printers.csv) based on your environment.

Example Output

When you run the script, you’ll see:

Creating TCP Port for OfficePrinter1 at 10.0.0.7
Adding printer OfficePrinter1
Creating TCP Port for OfficePrinter2 at 10.0.0.8
Adding printer OfficePrinter2
Creating TCP Port for OfficePrinter3 at 10.0.0.9
Adding printer OfficePrinter3
Printers have been added successfully!

Summary

Adding network printers to a print server or workstation can be tedious when using the GUI, especially when managing multiple devices. In this article, we demonstrated how PowerShell simplifies this process by allowing you to create TCP printer ports and printers efficiently.

We also walked through automating the setup using a CSV file, enabling you to add multiple printers and their associated ports in bulk. Whether you’re handling a single printer or scaling to dozens, this guide equips you with the tools to streamline your printer management tasks.