5

I'm working in a large environment writing a utility for a tech support team. I need to provide a list of all the print servers in the domain and let them pick one. Once they pick a print server, I will list all the print queues on that print server and have them select one. I have found plenty of examples of how to pull the list of print queues from the print server, but no examples of how to get a list of print servers.

How can I get a list of all the print servers in a domain (C#)?

ScottK
  • 51
  • 1
  • 2

3 Answers3

1

You can use the System.Management Namespace.

Please refer to this thread:
Is there a .NET way to enumerate all available network printers?

Community
  • 1
  • 1
ems305
  • 1,030
  • 11
  • 7
  • Thanks for the response, but I don't see where that can help me get a list of print servers. I can get all printers, but in our environment, that would be thousands. I need to present a list of print servers and then once they select a print server, list the queues on that server. – ScottK Jun 25 '12 at 18:01
  • Take a look at the System.Print.PrinterServer namespace: http://msdn.microsoft.com/en-us/library/system.printing.printserver.aspx. This has a GetPrintQueue method. – ems305 Jun 25 '12 at 18:16
  • 3
    Exactly what I will use for the second half of the task. I have that piece covered. What I need is a way to get a list of all the print servers available. – ScottK Jun 25 '12 at 18:34
0

I am not sure if this helps, but you could look for all Computers in the network and check their name.

Like so:

// Reference System.DirectoryServices is needed

DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry computers in root.Children)
{
    foreach (DirectoryEntry computer in computers.Children)
    {
        if (computer.SchemaClassName == "Computer") {
            if (computer.Name.IndexOf("printer-prefix-or-so")==-1)
                Console.WriteLine(computer.Name);
        }                            
    }
}
winner_joiner
  • 12,173
  • 4
  • 36
  • 61
0

In PowerShell you can do the following:

Import-Module ActiveDirectory Get-ADObject -LDAPFilter "(&(&(&(uncName=*)(objectCategory=printQueue))))" -properties *|Sort-Object -Unique -Property servername |select servername

ragerory
  • 1,360
  • 1
  • 8
  • 27
ckcoon
  • 1
  • 1