OK, GetObject isn't really appropriate for this. This requires quite a bit more code to work properly.
First, your code is hard-coding the directory path to "search", as your code doesn't really do any searching at all. It also hard-codes the IP to use. That's bad because if that server is down or the IP changes, your search is going to fail. Also, if the directory path changes at all, your code has to be changed to accommodate the changes in the directory.
That is easily solved with a simple method:
Function GetDefaultNamingContext() As String
Dim rootDse As New DirectoryEntry("LDAP://rootDSE")
Dim domainDn = rootDse.Properties("DefaultNamingContext").Value.ToString
Return domainDn
End Function
Now, need a method to search for an AD User object by its samAccountName. That's quite a bit more complicated than a single line of code:
Function GetAdObjectForSamAccount(ByVal samAccountName As String)
If [String].IsNullOrEmpty(samAccountName) Then
Throw New ArgumentNullException(samAccountName)
End If
Dim context As String = GetDefaultNamingContext()
Using directory As New DirectoryEntry($"LDAP://{context}")
Using searcher As New DirectorySearcher(directory, $"samAccountName={samAccountName}")
searcher.SearchScope = SearchScope.Subtree
Dim result As SearchResult
Dim returnObject As DirectoryEntry = Nothing
result = searcher.FindOne
If result IsNot Nothing Then
returnObject = result.GetDirectoryEntry
End If
Return returnObject
End Using
End Using
End Function
Why do this? Because you can call this method from others that all might work with a User object somehow, but in different ways. Each of those methods can use this method to grab a User object for them just based on the samAccountName.
For example, a method to return the DisplayName for a particular samAccountName, or what you're calling the "logon name".
Function GetDisplayNameForSamAccount(ByVal samAccountName As String) As String
If [String].IsNullOrEmpty(samAccountName) Then
Throw New ArgumentNullException(samAccountName)
End If
Dim displayName As String = String.Empty
Dim adObject As DirectoryEntry = GetAdObjectForSamAccount(samAccountName)
If adObject IsNot Nothing Then
displayName = adObject.Properties("DisplayName")(0).ToString
End If
Return displayName
End Function
And to call this and get the full name you're looking for is really easy:
Dim name As String = GetDisplayNameForSamAccount("BCNF0167")
Console.WriteLine($"DisplayName = {name}")