This batch file creates a number of organizational units (OU) in Active Directory. As the OU is defined by its distinghuised name, the organizational units will form a hierarchical tree of nested OU's.
The following script obviously assumes a certain design in the Active Directory : an Organizational Unit logical structure, users with membership to groups, therefore also a logical structure of somain local and global groups, etc. This is described in Active Directory Design and Implementation.
REM Koen Noens REM January 2003 REM Creating Active Directory Organizational Units set theDomain=dc=kicks, dc=local REM OU in domain dsadd ou "ou=theOffice, %theDomain%" REM OUs for Users in OU kantoor for %%i in (CT,PT,ST,FT,ND) do dsadd ou "ou=%%i, ou=theOffice, %theDomain%" ) REM additional statements : extra OUís dsadd ou "ou=_computers, ou=theOffice, %theDomain%" dsadd ou "ou=_printers, ou=theOffice, %theDomain%"
Windows 2003 Server comes with a new set of command which make Active Directory scripting far more straightforward. A text file such as the following,
"OU=FT,OU=kantoor,DC=KICKS,DC=LOCAL" "OU=ND,OU=kantoor,DC=KICKS,DC=LOCAL" "OU=IT,OU=kantoor,DC=KICKS,DC=LOCAL" "OU=computers,OU=kantoor,DC=KICKS,DC=LOCAL" "OU=printers,OU=kantoor,DC=KICKS,DC=LOCAL"
can be used to re-create the same OU's on an other machinbe / in an other domain :
For /L %%n in (ou.txt) do dsadd ou %%n
The input file in question can be easily produced by running Dsquery ou > ou.txt . See also getOU script.