ScottK
ScottK

Reputation: 51

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

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#)?

Upvotes: 5

Views: 5197

Answers (3)

ckcoon
ckcoon

Reputation: 1

In PowerShell you can do the following:

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

Upvotes: 0

winner_joiner
winner_joiner

Reputation: 14915

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

Upvotes: 0

ems305
ems305

Reputation: 1090

You can use the System.Management Namespace.

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

Upvotes: 1

Related Questions