VB Script to determine Active Directory Domain Mode

12/22/08

Permalink 08:50:07 pm, by dave Email , 604 words, 1081 views   English (US)
Categories: Windows Scripting, Wsh Scripts

VB Script to determine Active Directory Domain Mode

Recently, I needed a to determine if an Active Directory Domain was in native or mixed mode. After some research I came across a way to do this for Windows 2000 and 2003 domains. This script combines those two methods and can be used to determine the mode for Windows 2000 and 2003 domains. The one command line argument it expects is for the Windows 2000 domain mode determination. It works best if this script is executed from a machine that is member of the domain that is being queried.

[More:]

This sample script uses the named command line arguments to pass the domain information to script. This is the domain that will be checked for type, native or mixed mode.

'==========================================================
'==      Determine Windows Active Directory Mode Sample
'==
'==           Copyright © 2008, Dave Moats
'==
'== This sample is provided 'AS-IS', without any
'== express or implied warranty. In no event will the
'== authors be held liable for any damages arising from
'== the use of this sample code.
'==
'== Permission is granted to anyone to use this sample
'== code for any purpose, including commercial applications,
'== subject to the following restrictions:
'==
'== The origin of this code must not be misrepresented;
'== you must not claim that you wrote the original code.
'==
'== If you use this code, an acknowledgment in the
'== documentation is requested - shown below:
'==
'==             Portions Copyright © 2008,
'==        Dave Moats (http://www.davemoats.com/).
'==
'==========================================================

'==========================================================
'== NOTE: watch for wrapped lines and html special
'==        characters in the web representation of this
'==        sample code
'==========================================================

'==========================================================
'==
'== domainType.vbs - a script used to determine if a
'==                    windows 2000 or 2003 domain is
'==                    in mixed or native mode
'==
'==========================================================
option explicit

'==========================================================
'== declare the local variables to be used
'==========================================================
dim domainObj, rootDSE, domainParts, namedArgs
dim scriptName, domainName

'==========================================================
'== get the name of the running script
'==========================================================
scriptName = wscript.scriptname

'==========================================================
'== get the named command line arguments
'==========================================================
set namedArgs = wscript.arguments.named

if not namedArgs.exists("d") then
   wscript.echo "Usage: " & scriptName & " /d:<X500 domain path> is required"
   wscript.echo "Example: cscript " & scriptName & " /d:dc=subdomain,dc=domain,dc=com"
   wscript.quit
else
   domainName = namedArgs.item("d")
end if

set namedArgs = nothing

'==========================================================
'== check the ntMixedMode setting
'==========================================================
set domainObj = getobject( "LDAP://" & domainName )

if domainObj.nTMixedDomain = 0 Then
    wscript.echo "Windows Domain is in native mode."
else
    wscript.echo "Windows Domain is in mixed mode."
end if

set domainObj = nothing

'==========================================================
'== check domain configuration, msDS-Behaviour-Version
'==========================================================
set rootDSE = getobject( "LDAP://rootDSE" )

set domainParts = getobject( "LDAP://CN=Partitions," rootDSE.get( "configurationNamingContext" ))

if domainParts.[msDS-Behavior-Version] = 0 Then
    wscript.echo "This is a mixed-level forest."
elseif domainParts.[ msDS-Behavior-Version] = 1 Then
    wscript.echo "This is a Windows Server 2003 interim-level forest."
else
    wscript.echo "This is a Windows Server 2003 forest."
end if

set domainParts = nothing
set rootDSE = nothing

Pay close attention to the lines wrapping in this sample, the script does not have any multi-line statements.

I hope this post helped out. If it didn't, I am always looking for new scripts to add so submit a request for your question or need and I will see if I can answer it.

Dave



Did you like this post? If so, Share it!  del.icio.us digg reddit slashdot this article Facebook Twitter MySpace Email



Pingbacks:

No Pingbacks for this post yet...

This post has 2 feedbacks awaiting moderation...

Scripts

This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.

Search

Follow Me:

Misc

Who's Online?

  • Guest Users: 3

powered by b2evolution free blog software