dance2die
dance2die

Reputation: 36895

How to list all printers on network computer

As shown below in the picture, when I tried to retrieve all printers, I got only 2 printers.

Is there a way to return all printers using either PowerShell WMI or C#(so that I can translate it in powershell)?

I have tried System.Drawing.Printing.PrinterSettings.InstalledPrinters (refer to how to get the list of all printers in computer - C# Winform) but also displays only 2 entries.

enter image description here

Upvotes: 4

Views: 16864

Answers (1)

Ahmed Ghoneim
Ahmed Ghoneim

Reputation: 7057

Simply,

via System.Drawing.Printing

foreach (String printer in PrinterSettings.InstalledPrinters)
{
    Console.WriteLine(printer.ToString()+Environment.NewLine);
} 

via WMI

public static void AvailablePrinters()
{
 oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
 oManagementScope.Connect();

 SelectQuery oSelectQuery = new SelectQuery();
 oSelectQuery.QueryString = @"SELECT Name FROM Win32_Printer";

 ManagementObjectSearcher oObjectSearcher = 
    new ManagementObjectSearcher(oManagementScope, @oSelectQuery);
 ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();

 foreach (ManagementObject oItem in oObjectCollection)
 {

 Console.WriteLine("Name : " + oItem["Name"].ToString()+ Environment.NewLine);
 }
}

via PowerShell

Get-WMIObject -class Win32_Printer -computer $printserver | Select Name,DriverName,PortName

For more information, please check this article & WMI Printer Class

Upvotes: 3

Related Questions