Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting the Windows Script Host AddWindowsPrinterConnection Method

Windows PowerShell

Definition: Adds a Windows-based printer connection to your computer system.


At the moment Windows PowerShell has no cmdlets designed to help you manage printers. (Would that be a good thing for the PowerShell team to add? You bet it would.) However, you can use WMI to add a printer connection from within Windows PowerShell. This might not be the most intuitive bit of code you’ve ever seen, but it works:

$a = [wmiclass] Win32_Printer

So what’s going on here? Well, in line 1 we’re using the [wmiclass] type adapter to connect to the Win32_Printer class. Note that we are connecting directly to the class itself; we are not trying to retrieve data from the class. (That is, we don’t want to get back individual instances of the Win32_Printer class. That’s because the method we’re going to use, AddPrinterConnection, is a “static” method, which means it works on the class as a whole rather than instances of the class.) After we make the connection we call AddPrinterConnection, passing AddPrinterConnection the path to the printer in question.

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft