Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Converting the Windows Script Host EnumPrinterConnections Method


Windows PowerShell


Definition: Returns the current network printer mapping information.

EnumPrinterConnections


Windows Script Host’s EnumPrinterConnections method reports back the port name and printer name for each printer installed on a computer. (By the way, don’t let the official description throw you off; EnumPrinterConnections returns information about locally-installed printers as well as network printers). In other words, EnumPrinterConnections returns information similar to this:


USB001 = HP Photosmart C3100 series
LPT1: = HP Mobile Printing PS
IP_172.30.182.84 = \\atl-prn-corp1\b42-4032-a
XRX0000AA66FB35 = \\atl-prn-xrx\b42-4061-a
xrx0000aa6aa779 = \\atl-prn-xrx\b43-2927-a
XRX0000AA6AF4A4 = \\atl-prn-xrx.fabrikam.com\b43-2315-a


Can we get this same exact information using Windows PowerShell? You bet we can, provided we use the Get-WMIObject cmdlet to return the printer information, then use Select-Object to weed out everything except the PortName and Name properties:


Get-WMIObject Win32_Printer | Select-Object PortName, Name


Here’s the kind of output we get back when we run the preceding command:


USB001                           HP Photosmart C3100 series
LPT1:                            HP Mobile Printing PS
IP_172.30.182.84                 \\atl-prn-corp1\b42-4032-a
XRX0000AA66FB35                  \\atl-prn-xrx\b42-4061-a
xrx0000aa6aa779                  \\atl-prn-xrx\b43-2927-a
XRX0000AA6AF4A4                  \\atl-prn-xrx.fabrikam.com\b43-2315-a



See conversions of other Windows Script Host methods and properties.
Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.