On MP3.com: Top iPod Software

Collect domain names to automate admin script customization

Tags: Domain names, Guest Contributor, defaultNamingContext, domain name, domain

  • Save
  • Print
  • Recommend
  • 4

Takeaway: TechRepublic asked members to submit their favorite Network Administration scripts and this is one of the responses. You can use this script to automate the collection of enterprise-specific domain names required for the customization of other admin scripts.

TechRepublic recently asked members to submit their favorite Network Administration scripts for possible publication. One of the first to make a submission was Kevin Wood. For his effort, Kevin earned $100 and the satisfaction of seeing his script published on TechRepublic.


Earn $100 for your admin script

Let us pay you for your original scripts so that we can publish them as downloads on TechRepublic and allow your fellow IT professionals to benefit from your scripting savvy. We only ask that you put in the appropriate comments to your scripts so that it's easy to tell what the script is doing and which variables might need to be customized. Send us your original Windows admin scripts and we'll pay you $100 for each one that we publish as a TechRepublic download.


Here in his own words and code is Kevin's admin script:

Many scripts that you can download or get from other sources, hard code-in the domain information. To use the script quickly, one tends to merely hard code-in the current domain information.

If as a consultant, you travel from client to client, you change locations (and domains) frequently, re-keying the information becomes annoying. Also if I share a script, telling the recipient, change this line for your domain, becomes a necessity.

I have a script called GetDomain.vbs. (Listing A) It generates the domain name in a variety of ways. I merely copy the appropriate information into my scripts and voila—they are now domain generic and portable.

Listing A


--==[GetDomain.vbs]==--

'get the DNS domain name and the netbios domain name

'* find domain name - LDAP

   dim strBaseDN, strDNSDomain, oRootDSE

   Set oRootDSE = GetObject("LDAP://rootDSE")

   strBaseDN = "LDAP://" & oRootDSE.Get("defaultNamingContext")

   strDNSDomain = oRootDSE.Get("defaultNamingContext")

'* use this line " & strDNSDomain

   msgbox "User DNS domain = " & oRootDSE.Get("defaultNamingContext")

 

'* find domain name - Dotted - need LDAP domain as well for this part

   dim arrDomain, intCountstrDotDomain

   arrDomain = split(oRootDSE.Get("defaultNamingContext"), ",")

   for intCount = 0 to ubound(arrDomain)

    strDotDomain = strDotDomain &  "." & mid(arrDomain(intcount),4)

  next

    strDotDomain = mid(strDotDomain,2)

  msgbox "Dotted Domain = " & strDotDomain

 

'* find domain name - NetBIOS

  dim WshNetwork, strDomainName

  Set WshNetwork = WScript.CreateObject("WScript.Network")

  strDomainName = WshNetwork.UserDomain

 

  msgbox "User NetBIOS domain = " & WshNetwork.UserDomain

 

  • Save
  • Print
  • Recommend
  • 4

Print/View all Posts Comments on this article

Admin scripts: Automate domain name search Mark W. KaelinTechrepublic Moderator | 10/17/05
Simplified jonscott8 | 01/17/06

What do you think?

CIO Sessions

advertisement
Click Here