Get a list of all print servers in a C # domain

I work in a large environment, I write a program for technical support. I need to provide a list of all the print servers in the domain and let them choose one. After selecting the print server, I will list all print queues on this print server and select them. I have found many examples of how to get a list of print queues from a print server, but there are no examples of how to get a list of print servers. A.

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

+5
source share
3 answers

You can use the System.Management namespace.

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

+1

, , .

:

// 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);
        }                            
    }
}
0

In PowerShell, you can do the following:

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

0
source

All Articles