By Robbie Allen, Laura E. Hunter
Book Price: $49.99 USD
£35.50 GBP
PDF Price: $39.99
Cover | Table of Contents | Colophon
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 credentials can change over time, and as a security best practice you do not want the username and password contained in a script to be easily viewable by others. Nevertheless, it is a necessary evil, especially when developing against multiple forests, and we'll describe how it can be done with ADSI and ADO. As an alternative, you can configure a script to prompt you for the username and password during the actual running of the script.> dsquery /?
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl key. Create a new sub-key called KB. Underneath this subkey, create a REG_SZ value containing the following data:http://support.microsoft.com/?kbid=%s
> netsh wins server \\<WINSServerName> show name <DomainNetBiosName> 1b > netsh wins server \\<WINSServerName> show name <DomainNetBiosName> 1c > nslookup <DomainControllerDNSName > nslookup -type=SRV _ldap._tcp.gc._msdcs.<ForestDNSName > nslookup <ForestDNSName>
> netsh wins server \\<WINSServerName> show name <DomainNetBiosName> 1b > netsh wins server \\<WINSServerName> show name <DomainNetBiosName> 1c > nslookup <DomainControllerName> > nslookup -type=SRV _ldap._tcp.dc._msdcs.<DomainDNSName> > nslookup <DomainDNSName>
>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 ntdsutil because that server is responsible for creation and removal of domains.>ntdsutil "metadata cleanup" "select operation target" connections "connect to server <DomainControllerName>" quit quit metadata cleanup: "select operation target" "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: select domain 2 No current site Domain - DC=emea,DC=rallencorp,DC=com No current server No current Naming Context select operation target: quit metadata cleanup:
> ntdsutil "d m" "sel op tar" c "co t s<DomainControllerName>"
q "l d" q q q
> dsquery * -filter "objectcategory=domainDNS" -scope subtree
> adfind –root –s subtree –f "objectcategory=domainDNS" -dn ' This code gets the list of the domains contained in the
' forest that the user running the script is logged into.
strForestRoot = "<ForestRootDN>" ' i.e., dc=rallencorp, dc=com
strADsPath = "<LDAP://cn=Partitions,cn=Configuration," & _
strForestRoot & ">;"
strFilter = "(netbiosname=*);"
strAttrs = "dnsRoot;"
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
For Each root in objRS.Fields("dnsRoot").Value
WScript.Echo(root)
Next
objRS.MoveNext
wend > ntdsutil "domain management" "select operation target" connections "connect
to server<DomainControllerName>" quit "List domains" quit quit quitPartitions container for crossRef objects that refer to domain objects within the forest.Partitions container (e.g., cn=partitions,cn=configuration,dc=rallencorp, dc=com). (&(objectcategory=crossref)(dnsHostName=<DomainDNSName>)(netbiosname=*))> dsquery * cn=partitions,cn=configuration,<ForestRootDN> -filter "(&(objectcategory=crossref)(dnsroot=<DomainDNSName>)(netbiosname=*))" -attr netbiosname
> adfind -b cn=partitions,cn=configuration,<ForestRootDN> -f "(&(objectcategory=crossref)(dnsroot=<DomainDNSName>))" cn 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 dn:<DomainDN>
changetype: modify
replace: ntMixedDomain
ntMixedDomain: 0
-> ldifde -i -f change_domain_mode.ldf
> admod -b dc=rallencorp,dc=com "ntMixedDomain::0"
' 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 if > dsquery *<DomainDN> -scope base -attr msDS-Behavior-Version> msDS-Behavior-Version > 0
> adfind -s Base -b<DomainDN> msDS-Behavior-Version> AdFind V01.27.00cpp Joe Richards (joe@joeware.net) November 2005 > > Using server: dc1.rallencorp.com:389 > Directory: Windows Server 2003 > > dn:dc=rallencorp,dc=com >> msDS-Behavior-Version: 0 > > > 1 Objects returned
dn:<DomainDN>
changetype: modify
replace: msDS-Behavior-Version
msDS-Behavior-Version: 2
-> ldifde -i -f raise_domain_func_level.ldf
> admod -b dc=rallencorp,dc=com "msDS-Behavior-Version::2" > > AdMod V01.06.00cpp Joe Richards (joe@joeware.net) June 2005 > > DN Count: 1 > Using server: dc1.rallencorp.com > Modifying specified objects… > DN: dc=rallencorp,dc=com… > > The command completed successfully
' 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 > adfind -b<ForestRootDN> -s base ms-DS-Behavior-Version
>
> AdFind V01.27.00cpp Joe Richards (joe@joeware.net) November 2005
>
> Using server: dc1.rallencorp.com:389
> Directory: Windows Server 2003
>
> dn:cn=Partitions,CN=Configuration,dc=rallencorp,dc=com
> >ms-DS-Behavior-Version: 0
>
>
> 1 Objects returned dn: cn=partitions,cn=configuration,<ForestRootDN>
changetype: modify
replace: msDS-Behavior-Version
msDS-Behavior-Version: 2
-> ldifde -i -f raise_forest_func_level.ldf
> admod -b<ForestDN> "msDS-Behavior-Version::2"> AdMod V01.06.00cpp Joe Richards (joe@joeware.net) June 2005 > > DN Count: 1 > Using server: dc1.rallencorp.com > Modifying specified objects… > DN: cn=Partitions,cn=Configuration,dc=rallencorp,dc=com… > > The command completed successfully
' 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 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
logfiles located at %SystemRoot%\System32\Debug\Adprep\Logs.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.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 /forestprep command extends the schema and modifies some default security descriptors, which is why it must run on the Schema FSMO and under the credentials of someone in both the Schema Admins and Enterprise Admins groups. In addition, the adprep /forestprep and /domainprep commands add new objects throughout the forest, many of which are necessary for new features supported in Windows Server 2003 Active Directory.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>