Wednesday, May 13, 2009

A Chevy is a Chevy, even in China

Have you ever spent a few minutes watching a TV channel that is entirely in a language other than your own?  Ever notice how in the middle of blabbering away about something, you can still pick out familiar terms like "McDonald's" or "Pepsi" or "Chevrolet"?  That's because some words just don't have a translation, so they use the original in every other language.  It goes both ways.  We say "Latte" and "Kayak" and "Lasagna" even in America.

What does this have to do with scripting or programming? Well, sometimes a piece of code just ends up being the same thing no matter what language you try to hammer it into.  Let's consider the RootDSE object provided by your friendly neighborhood Active Directory interface.  You use it (or should) when you need to query information from AD, such as users, groups, or computers.  It can give you way more than that, but those are just quick examples.

The first step is to bind to the RootDSE object and then you can start asking for information from it.  In this case, I want obtain the various naming context object values, as well as the DNS name.  Let's do this in each language, shall we?  Lets!

VBScript

Set objRootDSE = GetObject("LDAP://rootDSE")
Wscript.Echo "defaultNamingContext = " & objRootDSE.Get("defaultNamingContext")
Wscript.Echo "rootdomainNamingContext = " & objRootDSE.Get("rootDomainNamingContext")
Wscript.Echo "configurationNamingContext = " & objRootDSE.Get("configurationNamingContext")
Wscript.Echo "dnsHostName = " & objRootDSE.Get("dnsHostName")

KiXtart

$objRootDSE = GetObject("LDAP://rootDSE") 
?" defaultNamingContext = " + $objRootDSE.Get("defaultNamingContext")
?" rootdomainNamingContext = " + $objRootDSE.Get("rootDomainNamingContext")
?" configurationNamingContext = " + $objRootDSE.Get("configurationNamingContext")
?" dnsHostName = " + $objRootDSE.Get("dnsHostName")

PowerShell v2.0

$rootDSE = [ADSI]"LDAP://RootDSE"
"defaultNamingContext = " + $rootDSE.defaultNamingContext
"rootdomainNamingContext = " + $rootDSE.rootDomainNamingContext
"configurationNamingContext = " + $rootDSE.configurationNamingContext
"dnsHostName = " + $rootDSE.dnsHostName

As you can see, they are remarkably similar.  There's just not a lot you can do different between them.  The only meaningful difference is that each language provides somewhat more succinct coding than the one above it.  Wscript.Echo becomes ? and then becomes implicit in the last example.  Interesting, but nothing to write home about.  I think I'll stare at this and rub my chin for a few minutes.  Pretend I'm pondering the style of a painting hanging in a museum.

No comments: