I have find the Ipaddress and Hostname using the active directory ComputerPrincipal method.but not find the username in this method.i need the username in my domain .how to do this?
here it my code
namespace Directory
{
class Program
{
static void Main(string[] args)
{
using (var context = new PrincipalContext(ContextType.Domain, "xxx.com"))
{
using (var searcher = new PrincipalSearcher(new ComputerPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
var auth = result as AuthenticablePrincipal;
var userName = auth.UserPrincipalName;
if (auth != null)
{
Console.WriteLine("Name: " + auth.Name);
Console.WriteLine("Last Logon Time: " + auth.LastLogon);
Console.WriteLine("UserName: " + auth.UserPrincipalName);
if (auth.Name != "Txx-Cxx-Gxx-Pxx")
{
IPAddress[] ipaddress = Dns.GetHostAddresses(auth.Name);
foreach (IPAddress ipaddr in ipaddress)
{
Console.WriteLine(ipaddr);
}
Console.WriteLine();
}
else
{
Console.WriteLine("Error");
}
}
}
}
Console.ReadLine();

Rajeesh MenothRank #118 · 18.4K reputationPosted Jan 2, 2019, 8:15 PM EST
Sanwar RanwaRank #23 · 44.7K reputationPosted Jan 10, 2019, 5:24 PM EST