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
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