Richard
Thu Sep 18 14:11:11 CDT 2003
"Richard Mueller [MVP]" <rlmueller@ameritech.net> wrote in message
news:uFAQ9AhfDHA.944@TK2MSFTNGP11.phx.gbl...
> Dennis Arvidson wrote:
>
> > I am trying to figure out how to write a script that returns the active
> > directory dns domain name from NetBIOS domain name. The domain may or
may
> > not be in the same forest.
> >
> > For example: pass in domain name "regionaldom" and get back
> > "regionaldom.globalname.com", where the root domain is "globalname.com".
>
> Hi,
>
> I use the NameTranslate object, as follows:
>
> strNetBIOSDomain = "regionaldom"
> Set objTrans = CreateObject("NameTranslate")
> objTrans.Init 1, strNetBIOSDomain
> objTrans.Set 3, strNetBIOSDomain & "\"
> strDNSDomain = objTrans.Get(1)
> Wscript.Echo "DNS domain name: " & strDNSDomain
>
> I don't know how this would work if the domain is not in the same forest.
> Another approach would be to use ADO to search for the object in the
> Configuration container of AD in the other domain that has the given
NetBIOS
> name and return the DNS name.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> HilltopLab web site -
http://www.rlmueller.net
> --
Hi,
Based on a script by Robbie Allen (that converted the DNS domain name to the
NetBIOS name), here is a script that seems to convert from the NetBIOS
domain name to the DNS name, using ADO to search the "cn=Partitions"
container of the "cn=Configuration" container of AD:
Option Explicit
Dim strDomain, objRootDSE, strBase, strFilter, strAttributes, strScope
Dim strQuery, objConnection, objRecordSet
strDomain = "regionaldom"
Set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
strBase = "<LDAP://" & strDomain & "/cn=Partitions," _
& objRootDSE.Get("configurationNamingContext") & ">"
strFilter = "(&(objectCategory=CrossRef)" _
& "(netBIOSName=" & strDomain & "))"
strAttributes = "nCName"
strScope = "OneLevel"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objRecordSet = objConnection.Execute(strQuery)
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "DNS Name for " & strDomain & " is " _
& objRecordSet.Fields("nCName")
objRecordSet.MoveNext
Loop
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site -
http://www.rlmueller.net
--