Adding Network printers to a print server can be cumbersome when doing it through the GUI. For that reason, you may want to attempt to do it via a CLI interface. In this article I describe the Powershell commands for adding a TCP port for a TCP printer. As well as how to bulk create the TCP printer ports using a Powershell For loop.
Syntax
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:
Add-PrinterPort -Name “ip_10.0.0.7″ -PrinterHostAddress 10.0.0.7
As you can see, 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, bere is a powershell script that will read in a CSV, then create printer ports for each entry in the csv file:
#Import CSV file
$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
$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
Summary
In this article, we have discussed how to create tcp printer ports using powershell. And we have discussed how to import a CSV full of IP addresses, and create a TCP printer port for each IP in the CSV file.