To get the default printer installed on a computer using the PowerShell, use the `Get-WmiObject
` cmdlet. The Get-WmiObject command uses the Win32_Printer class that represents a printer object in WMI.
Here is the PowerShell command to find the default printer installed on a computer.
Get-WmiObject -Class Win32_Printer | Where-Object {$_.Default -eq $True}
In the above PowerShell script, the Get-WmiObject command is used to get objects from the Windows Management Instrumentation (WMI) repository. This command retrieves the printer objects in WMI using the class Win_32 Printer.
It returns a list of all printers installed on the computer and pipes them to the Where-Object
command to find the default printer using $_.Default -eq $True
condition.
The output of the above PowerShell script that returns the default printer installed on the computer is given below.
If there is no printer installed on the computer, the Get-WmiObject
command will return an empty array.
You can also use the Get-WmiObject alias command gwmi to write a query in a short format to get the default printer in Windows 10.
gwmi win32_printer | WHERE {$_.Default -eq $True}
Cool Tip: How to get the printer properties using PowerShell!
Conclusion
I hope the above article on how to get the default printer installed on the Windows operating system using the PowerShell Get-WmiObject command is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.