Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.DirectoryServices;
- namespace GetLogs
- {
- class GetComputers
- {
- public static List<string> GetComputerNames()
- {
- GetComputers ComputerNames = new GetComputers();
- string domain = Environment.UserDomainName;
- DirectoryEntry entry = new DirectoryEntry("LDAP://"+domain);
- DirectorySearcher mySearcher = new DirectorySearcher(entry);
- mySearcher.Filter = ("(objectClass=computer)");
- mySearcher.SizeLimit = int.MaxValue;
- mySearcher.PageSize = int.MaxValue;
- foreach (SearchResult resEnt in mySearcher.FindAll())
- {
- //"CN=SGSVG007DC"
- string ComputerName = resEnt.GetDirectoryEntry().Name;
- if (ComputerName.StartsWith("CN="))
- ComputerName = ComputerName.Remove(0, "CN=".Length);
- ComputerNames.Add(ComputerName);
- }
- mySearcher.Dispose();
- entry.Dispose();
- return ComputerNames;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment