Reputation: 51
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
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
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
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