Cover | Table of Contents | Colophon
http://support.microsoft.com/)
articles, or documentation from the Microsoft Developers
Network (MSDN) (http://msdn.microsoft.com).http://support.microsoft.com/)
articles, or documentation from the Microsoft Developers
Network (MSDN) (http://msdn.microsoft.com).http://www.microsoft.com/windows/reskits/. The Windows 2000 Support Tools, which is
called the Windows Support Tools in Windows Server 2003, contain many
"must have" tools for people that
work with Active Directory. The Microsoft installer (MSI) for the
Windows Support Tools can be found on a Windows 2000 Server or
Windows Server 2003 CD in the \support\toolsdirectory. The Appendix A contains a complete list of the
tools used within this book, where they can be found, and what
recipes they are used in.dsmod
tool can modify attributes on a limited set of object classes, but it
does not allow you to modify any object type.ldifde
utility has been available since
Windows 2000 and it allows you to import and export Active Directory
content in LDIF format. LDIF files are composed of blocks of entries.
An entry can add, modify, or delete an object. The first line of an
entry is the distinguished name. The second line contains a
changetype, which can be add,
modify, or delete. If it is an
object addition, the rest of the entry contains the attributes that
should be initially set on the object (one per line). For object
deletions, you do not need to specify any other attributes. And for
object modifications, you need to specify at least three more lines.
The first should contain the type of modification you want to perform
on the object. This can be add (to set a
previously unset attribute or to add a new value to a multivalued
attribute), replace (to replace an existing
value), or delete (to remove a value). The
modification type should be followed by a colon and the attribute you
want to perform the modification
on.
The next line should contain the name of the attribute followed by a
colon, and the value for the attribute. For example, to replace the
last name attribute with the value Smith, you'd use
the following LDIF:set objRootDSE = GetObject("LDAP://RootDSE")
set objRootDSE = GetObject("LDAP://apac.rallencorp.com/RootDSE")
set objRootDSE = GetObject("LDAP://dc1/RootDSE")
runas method described earlier when
invoking the script. A better option would be to use the Scheduled
Tasks service to run the script under credentials you specify when
creating the task. And yet another option is to hardcode the
credentials in the script. Obviously, this is not very appealing in
some scenarios because you do not want the username and password
contained in the script to be easily viewable by others.
Nevertheless, it is a necessary evil, especially when developing
against multiple forests, and I'll describe how it
can be done with ADSI and ADO./? as a parameter. For example:> dsquery /?
http://support.microsoft.com/default.aspx.
You can also append the KB article number to the end of this URL to
go directly to the article: http://support.microsoft.com/?kbid=.dcpromo from a command line or Start
→ Run.dcpromo can also be run in unattended mode. See
Recipe 3.4 for more details.dcpromo
executable to promote a Windows 2000 or Windows Server 2003 server to
be a domain controller for a new domain. The
dcpromo program has a wizard interface that
requires you to answer several questions about the forest and domain
you want to promote the server into. After dcpromo
finishes, you will be asked to reboot the computer to complete the
promotion process.dcpromo, all the domain controllers in the forest.
When you run dcpromo on an existing domain
controller, you will be given the option to demote the machine to a
member server. After that is completed and depending on how your
environment is configured, you may need to remove WINS and DNS
entries that were associated with the domain controllers and domains
unless they were automatically removed via WINS deregistration and
dynamic DNS (DDNS) during demotion. The following commands can help
determine if all entries have been removed:> netsh wins server \\<WINSServerName> show name <ForestDNSName> 1c > nslookup <DomainControllerDNSName> > nslookup -type=SRV _ldap._tcp.gc._msdcs.<ForestDNSName> > nslookup <ForestDNSName>
dcpromo from a
command line or Start → Run.dcpromo can also be run
in
unattended mode. See Recipe 3.4 for more
details.dcpromo offers to create a new
domain are adding the domain to an existing domain tree or starting a
new domain tree. If you want to create a new domain that is a
subdomain (contained within the same namespace) of a parent domain,
you are creating a domain in an existing domain tree. If you are
creating the first domain in a forest or a domain outside the
namespace of the forest root, you are creating a domain in a new
domain tree.dcpromo
on the domain controllers and following the steps to remove them. For
the last domain controller in the domain, be sure to select
"This server is the last domain controller in the
domain" in the dcpromo wizard so
that the objects associated with the domain get removed. If you do
not select that option for the last domain controller in the domain,
take a look at Recipe 2.5 for how to remove
an orphaned domain.> netsh wins server \\<WINSServerName> show name <DomainDNSName> 1c > nslookup <DomainControllerName> > nslookup -type=SRV _ldap._tcp.dc._msdcs.<DomainDNSName> > nslookup <DomainDNSName>
ntdsutil
commands (in bold) would forcibly
remove the emea.rallencorp.com
domain from the rallencorp.com
forest. Replace
<DomainControllerName> with the
hostname of the Domain Naming Flexible Single Master Operation (FSMO)
for the forest:
> ntdsutil "meta clean" "s o t" conn "con to server <
DomainControllerName
>" q q
metadata cleanup: "s o t" "list domains"
Found 4 domain(s)
0 - DC=rallencorp,DC=com
1 - DC=amer,DC=rallencorp,DC=com
2 - DC=emea,DC=rallencorp,DC=com
3 - DC=apac,DC=rallencorp,DC=com
select operation target: sel domain 2
No current site
Domain - DC=emea,DC=rallencorp,DC=com
No current server
No current Naming Context
select operation target: q
metadata cleanup: remove sel domain
crossRef object
in the Partitions container. You need to target
the Domain Naming FSMO when using the ntdsutil
command because that server is responsible for creation and removal
of domains.
[RETURN]> ntdsutil "d m" "sel op tar" c "co t s <DomainControllerName>" q "l d" q q q
' This code gets the list of the domains contained in the
' forest that the user running the script is logged into.
set objRootDSE = GetObject("LDAP://RootDSE")
strADsPath = "<GC://" & objRootDSE.Get("rootDomainNamingContext") & ">;"
strFilter = "(objectcategory=domainDNS);"
strAttrs = "name;"
strScope = "SubTree"
set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
set objRS = objConn.Execute(strADsPath & strFilter & strAttrs & strScope)
objRS.MoveFirst
while Not objRS.EOF
Wscript.Echo objRS.Fields(0).Value
objRS.MoveNext
wend
ntdsutil example, shortcut parameters were
used to reduce the amount of typing needed. If each parameter were
typed out fully, the command line would look like:> ntdsutil "domain management" "select operation target" connections "connect
> dsquery * cn=partitions,cn=configuration,<ForestRootDN> -filter[RETURN] "(&(objectcategory=crossref)(dnsroot=<DomainDNSName>)(netbiosname=*))" -attr[RETURN] netbiosname
' This code prints the NetBIOS name for the specified domain
' ------ SCRIPT CONFIGURATION ------
strDomain = "<DomainDNSName>" ' e.g. amer.rallencorp.com
' ------ END CONFIGURATION ---------
set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
strADsPath = "<LDAP://" & strDomain & "/cn=Partitions," & _
objRootDSE.Get("configurationNamingContext") & ">;"
strFilter = "(&(objectcategory=Crossref)" & _
"(dnsRoot=" & strDomain & ")(netBIOSName=*));"
strAttrs = "netbiosname;"
strScope = "Onelevel"
set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
set objRS = objConn.Execute(strADsPath & strFilter & strAttrs & strScope)
objRS.MoveFirst
WScript.Echo "NetBIOS name for " & strDomain & " is " & objRS.Fields(0).Value
http://www.microsoft.com/windowsserver2003/downloads/domainrename.mspx
> dsquery * <DomainDN> -scope base -attr ntMixedDomain
enumprop command found in the
Windows 2000 Resource Kit.> enumprop /ATTR:ntMixedDomain "LDAP://<DomainDN>"
dn: <DomainDN>
changetype: modify
replace: ntMixedDomain
ntMixedDomain: 0
-
ldifde command to import the change.> ldifde -i -f change_domain_mode.ldf
' This code changes the mode of the specified domain to native
' ------ SCRIPT CONFIGURATION ------
strDomain = "<DomainDNSName>" ' e.g. amer.rallencorp.com
' ------ END CONFIGURATION ---------
set objDomain = GetObject("LDAP://" & strDomain)
if objDomain.Get("nTMixedDomain") > 0 Then
Wscript.Echo "Changing mode to native . . . "
objDomain.Put "nTMixedDomain", 0
objDomain.SetInfo
else
Wscript.Echo "Already a native mode domain"
end ifEnterprise
Admins and Schema Admins groups:> adprep /forestprep
/forestprep have replicated
throughout the forest (see Recipe 2.11), run
the following command on the Infrastructure FSMO in each domain with
the credentials of an account in the Domain Admins
group:> adprep /domainprep
/forestprep have not
replicated to at least the Infrastructure FSMO servers in each
domain, an error will be returned when running
/domainprep. To debug any problems you encounter,
see the ADPrep log files located at %SystemRoot%\System32\Debug\Adprep\Logs.adprep can be found in the \i386 directory on the Windows Server 2003
CD. The tool relies on several files in that directory, so you cannot
simply copy that file out to a server and run it. You must either run
it from a CD or from a location where the entire directory has been
copied.adprep command prepares a Windows 2000 forest
and domains for Windows Server 2003. Both
/forestprep and /domainprep
must be run before you can upgrade any domain controllers to Windows
Server 2003 or install new Windows Server 2003 domain controllers.The
adprep command serves a
similar function to the Exchange 2000 setup
/forestprep and /domainprep
commands, which prepare an Active Directory forest and domains for
Exchange 2000. The adprep
adprep /domainprep completed,
check for the existence of the following object where
<DomainDN> is the distinguished name
of the domain:cn=Windows2003Update,cn=DomainUpdates,cn=System,<DomainDN>
adprep /forestprep completed,
check for the existence of the following object where
<ForestRootDN> is the distinguished
name of the forest root domain:cn=Windows2003Update,cn=ForestUpdates,cn=Configuration,<ForestRootDN>
adprep utility is used to prepare a Windows 2000
forest for the upgrade to Windows Server 2003. One of the nice
features of adprep is it stores its progress in
Active Directory. For /domainprep, a container
with a distinguished name of cn=DomainUpdates,cn=System,<
DomainDN
>
is created that has child object containers
cn=Operations and
cn=Windows2003Update. After
adprep completes a task, such as extending the
schema, it creates an object under the
cn=Operations container to signify its completion.
Each object has a GUID for its name, which represents some internal
operation for adprep. For
/domainprep, 52 of these objects are created.
After all of the operations have completed successfully, the
cn=Windows2003Update object is created to indicate
/domainprep has completed.Figure 2-2 shows an example of the container structure
created by /domainprep.
/forestprep, a container with the
distinguished name of > winnt32 /checkupgradeonly
/checkupgradeonly switch simulates the initial
steps for upgrading a server to Windows Server 2003. It verifies,
among other things, that adprep has completed and
that any installed applications are compatible with the new operating
system.adprep has completed and MS KB 331161 (List of
Fixes to Use on Windows 2000
Domain Controllers Before You Run
the Adprep/Forestprep Command)> dsquery * <DomainDN> -scope base -attr msDS-Behavior-Version
enumprop command found in the
Windows 2000 Resource Kit.> enumprop /ATTR:msDS-Behavior-Version "LDAP://<DomainDN>"
raise_domain_func_level.ldf with the
following contents:dn: <DomainDN>
changetype: modify
replace: msDS-Behavior-Version
msDS-Behavior-Version: 2
-
ldifde command to import the change.> ldifde -i -f raise_domain_func_level.ldf
' This code changes the functional level of the specified domain to ' the Windows Server 2003 domain functional level ' ------ SCRIPT CONFIGURATION ------ strDomain = "<
> dsquery * <ForestRootDN> -scope base -attr msDS-Behavior-Version
enumprop command found in the
Windows 2000 Resource Kit.> enumprop /ATTR:msDS-Behavior-Version "LDAP://<ForestRootDN>"
raise_forest_func_level.ldf with the
following contents:dn: cn=partitions,cn=configuration,<ForestRootDN>
changetype: modify
replace: msDS-Behavior-Version
msDS-Behavior-Version: 2
-
ldifde command to import the change.> ldifde -i -f raise_forest_func_level.ldf
' This code changes the functional level of the the forest the
' user running the script is logged into to Windows Server 2003.
set objRootDSE = GetObject("LDAP://RootDSE")
set objDomain = GetObject("LDAP://cn=partitions," & _
objRootDSE.Get("configurationNamingContext") )
if objDomain.Get("msDS-Behavior-Version") <> 2 then
Wscript.Echo "Attempting to change forest to " & _
"Windows Server 2003 functional level . . . "
objDomain.Put "msDS-Behavior-Version", 2
objDomain.SetInfo
else
Wscript.Echo "Forest already at Windows Server 2003 functional level"
end if> netdom trust <NT4DomainName> /Domain:<ADDomainName> /ADD[RETURN] [/UserD:<ADDomainName>\ADUser> /PasswordD:*][RETURN] [/UserO:<NT4DomainName>\NT4User> /PasswordO:*][RETURN] [/TWOWAY]
> netdom trust <Forest1DNSName> /Domain:<Forest2DNSName> /Twoway /Transitive /ADD[RETURN] [/UserD:<Forest2AdminUser> /PasswordD:*][RETURN] [/UserO:<Forest1AdminUser> /PasswordO:*]
> netdom trust rallencorp.com /Domain:othercorp.com /Twoway /Transitive /ADD[RETURN] /UserD:administrator@othercorp.com /PasswordD:*[RETURN] /UserO:administrator@rallencorp.com /PasswordO:*