I'm working with Active Directory, and I must recognise the owner of a specific computer.
With the code below I can find this computer by the "CN" name:
string ldapString = $"LDAP://OU=*****,DC=*****,DC=*****";
DirectoryEntry entry = new(ldapString);
DirectorySearcher search = new(entry);
search.SearchScope = SearchScope.Subtree;
search.Filter = $"(&(objectClass=computer)(CN={computerName}))";
var result = search.FindOne();
I found a solution here How do you get the Owner of a Computer in AD? (with .NET Core) how can i get the company as owner but i need a user (employee) samAccounName or userPrincipalName who last used it?
Is it possible or not to get the last user of the found computer? Thanks!