VB Script to determine Active Directory Domain Mode
12/22/08
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.
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.namedif 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 ifset 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 ifset 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 ifset 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
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:
Categories
- All
- Web Technologies (2)
- PHP (1)
- Windows Scripting (37)
- Batch Scripts (13)
- Wsh Scripts (23)
Archives
- December 2009 (2)
- March 2009 (2)
- February 2009 (3)
- January 2009 (2)
- December 2008 (4)
- November 2008 (1)
- October 2008 (1)
- February 2008 (1)
- December 2007 (3)
- July 2007 (1)
- April 2007 (1)
- February 2007 (2)
- More...
Misc
Who's Online?
- Guest Users: 3




