The job of System Administrators are very adventurous, sometime you have to find a little-little settings and sometime you have to write a big-big, hundred’s of line’s scripts.
Today, my task was to find a default printer installed on laptops. To solve it , i used the Win32_Printer class.
You can run the below query on your laptop and this will show you the default installed printer on your system.
To run the below command on the remote system you can –Computer parameter and make sure you are proper admin rights to access the system.
We are using Get-WmiObject cmdlet and then we are running a WQL query to select everything from Win32_Printer class and choose to show that result where default value is true.
Simple
Get-WmiObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" |
If you want to see all printers installed on your laptop, you can run the below code and this will show you the list of all printers, with their Port Name and location.
Get-WmiObject -Query " SELECT * FROM Win32_Printer" | Select Name, Default, PortName,Location |
I love WMI .
Happy learning . ;o) .
Tested on : Windows7 [64 bit]
In a domain with some computers, is it possible to get all default printer with this PS command?
ReplyDeleteThanks
How to run this command for remote pc
ReplyDeletePlease share syntax to run these commands in domain
ReplyDeleteThis can become quite a bit shorter with a couple small changes:
ReplyDelete1) Get-Wmi-Object has an alias gwmi
2) instead of writing out your whole query -Query "SELECT * FROM Win32_Printer" you can just use Win32_Printer
So you end up with:
gwmi win32_printer | WHERE {$_.Default -eq $True}
and
gqmi Win32_Printer | Select Name, Default, PortName, Location