Ramya k

Ramya k

  • NA
  • 14
  • 2.6k

how to find the Ipaddress using username ?

Jan 2 2019 6:47 AM
here it my code
 
namespace Active_Directory
{
class Program
{
static void Main(string[] args)
{
using (var context = new PrincipalContext(ContextType.Domain, "xxx.com"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
string name = de.Properties["samAccountName"].Value.ToString();
if (name == "xxxx")
{
Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value);
Console.WriteLine("User Principal Name: " + de.Properties["UserPrincipalName"].Value);
Console.WriteLine();
}
}
}
}
Console.ReadLine();
}
}
}
 

Answers (1)