Freigeben über


Use PowerShell to Create New Printer Ports

Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell 3.0 to create new printer ports in Windows 8.
Microsoft Scripting Guy, Ed Wilson, is here. One of the exciting things that is happening around the Scripting House is the appearance of new Windows PowerShell Saturday events. We have new events coming up in Atlanta, Singapore, and Charlotte. For information about these and other events, check out my site, Scripting Community . If you do not know what Windows PowerShell is, check out my blog post, Community: All about PowerShell Saturday .
To programmatically create a working printer, there are at least three steps:

Create the printer port.
Install the printer driver.
Install the printer (by using the printer port and the printer driver).

Today I am talking about creating the printer port.
Using PowerShell to work with printer ports
Before I create anything, I like to know what I have going on with my computer. I can use the Get-PrinterPort function to list existing printer ports on my local computer:
Get-PrinterPort
I can also use this function to retrieve printer port information from a remote server running Windows Server 2008 and Windows PowerShell 3.0 as shown here:
Get-PrinterPort -ComputerName dc1
The commands and the output from the commands are shown in the following image.

Adding a new printer port
To add a new printer port, I use the Add-PrinterPort function in Windows 8 or Windows Server 2012. By using the Add-PrinterPort function, I can add a local printer port, a TCP printer port, or an LPR printer port.
Most of the time, if I am creating a local printer port, I want to print directly to a printer on the network. Doing this bypasses a print server. Therefore, in the case of large print jobs, I lose flexibility because my laptop must remain on to manage the large print job. But for short documents, it is fast. Also by printing directly to the printer, I can configure things the way that I want.
By using Windows PowerShell, it is easy to create a TCP printer port. I use the Add-PrinterPort function, create a name for the port (the name does not matter, but it is best to use something that makes sense in the printing context). The IP address of the printer itself becomes the value for the PrinterHostAddress parameter. Here is the command I used:
Add-PrinterPort -Name 'HP_Direct:' -PrinterHostAddress '192.168.1.88'
I do not need to specify a value for the port...(read more)