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.
The syntax for adding the TCP print port via PowerShell is as follows:
Add-PrinterPort -Name "ip_IPAddress" -PrinterHostAddress IPAddress
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
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:
| PrinterName | IP | DriverName |
|---|---|---|
| OfficePrinter1 | 10.0.0.7 | HP Universal Printing PCL 6 |
| OfficePrinter2 | 10.0.0.8 | HP Universal Printing PCL 6 |
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
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 :
# powershell add universal printer
Add-Printer -Name "Office Printer" -DriverName "HP Universal Printing PCL 6" -PortName "IP_10.0.0.7"
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.
Save this as printers.csv:
| PrinterName | IPAddress | DriverName |
|---|---|---|
| OfficePrinter1 | 10.0.0.7 | HP Universal Printing PCL 6 |
| OfficePrinter2 | 10.0.0.8 | Canon Generic Printer |
| OfficePrinter3 | 10.0.0.9 | Brother HL-2270DW Series |
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!"
Import-Csv cmdlet reads the printers.csv file, creating objects for each row where columns like PrinterName, IPAddress, and DriverName become properties.Add-PrinterPort cmdlet.Add-Printer cmdlet, associating it with the specified port and driver.Write-Host: Provides status updates for each printer during execution.Get-PrinterDriver to list all available drivers.C:\printers.csv) based on your environment.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!
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.