Was this page helpful?
Your feedback about this content is important. Let us know what you think.
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 SetDefaultPrinter Method

Windows PowerShell

Definition: Assigns a remote printer the role Default Printer.


You know, you’re right: life would be awfully dull if you always kept the same default printer, wouldn’t it? Fortunately you can use WMI and the Get-WMIObject cmdlet to change the default printer on a computer. The following block of code uses Get-WMIObject – and the –query parameter – to retrieve a collection of all the printers on the computer named Test Printer. (Because printer names must be unique on a computer, there will only be one item in the collection.) Once the printer has been returned the second line of code uses the SetDefaultPrinter method to make Test Printer the default printer on the computer:

$a = Get-WMIObject -query "Select * From Win32_Printer Where Name = 'Test Printer'"

Unlike Windows Script Host, PowerShell – and WMI – can be used to assign a default printer on a remote computer. To do that, just add the –computerName parameter followed by the name of the remote machine:

$a = Get-WMIObject -computerName atl-ws-001 -query "Select * From Win32_Printer Where Name = 'Test Printer'"

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