Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NetBIOSName of domain name by User

Status
Not open for further replies.

alpweb

MIS
May 1, 2009
2
CA
trying to get netbiosname of domain, by user , i have below code which gets me netbiosname , but i don't know how to get it by username

Code -- to get netbios name

Dim objConnection, objRootDSE, objRecordSet
Dim strFilter

strFilter = "(NETBIOSName=*)"

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objRootDSE = GetObject("LDAP://RootDSE")
Set objRecordSet = objConnection.Execute( _
"<LDAP://" & objRootDSE.Get("configurationNamingContext") & ">;" & _
strFilter & ";" & "NETBIOSName,dnsroot,ncname;subtree")
Set objRootDSE = Nothing

While Not objRecordSet.EOF
Wscript.Echo Join(objRecordSet.Fields("dnsroot").Value)
Wscript.Echo objRecordSet.Fields("ncname").Value
Wscript.Echo objRecordSet.Fields("NETBIOSName").Value

objRecordSet.MoveNext
Wend


--- below is my actual code where i search user by last,first name , which returns all details except NetBiosname of the domain
- we have multiple domains, so when i search for any user, user might be on any domain , user CN have different name then biosname, for example.

DC=abc,DC=ad,DC=in,DC=xx,DC=yy -user logs in to AbcInc
DC=dep,DC=ad,DC=in,DC=xx,DC=yy -user logs in to DepInc

Const ADS_SECURE_AUTHENTICATION = 1

Dim oGC As IADsContainer
Dim oEntrprise As IADs
Dim oConn, oComm, child, oRs As Recordset

Dim column_header As ColumnHeader
' Get the enterprise object from the GC namespace.
Set oGC = GetObject("GC:")
For Each child In oGC
Set oEntrprise = child
Exit For
Next

' Setup ADO.
Set oConn = CreateObject("ADODB.Connection")
Set oComm = CreateObject("ADODB.Command")

oConn.Provider = "ADsDSOObject"
oConn.Properties("ADSI Flag") = ADS_SECURE_AUTHENTICATION

oConn.Open
oComm.ActiveConnection = oConn
Dim ParLastN, ParFirstN
ParLastN = LastN
ParFirstN = FirstN


oComm.CommandText = "<" & oEntrprise.ADsPath & ">;(&(objectCategory=person)(objectClass=user)(givenName=" & _
ParFirstN & "*)(sn=" & ParLastN & "*));" & _
"sAMAccountName,displayName,distinguishedName,userPrincipalName,canonicalName,mail,streetAddress,l,postalCode,TelephoneNumber,homeMDB,memberof,mail;subTree"

Set oRs = oComm.Execute


- on result set i loop through number of record found and display them in the listview , in here its very difficult for me to identify which user logs in to which domain

thanx





 
That should be available to you as objUser.DC.

Add DC to the properties you retrieve in here:

"sAMAccountName,displayName,dc, distinguishedName,userPrincipalName,canonicalName,mail,streetAddress,l,postalCode,TelephoneNumber,homeMDB,memberof,mail;subTree"


I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top