In this mini-post, I want to show you how to perform an offline defragmentation of the Active Directory database. To perform the maintenance of the AD DS database offline, we will use the NtdsUtil.exe command line tool. At the end of the defragmentation, we will obtain a compact AD DS database.
Requirements: The minimum required to complete the following tasks is Membership in the Local Administrators group.
Important: Before performing the tasks described in this post, you must perform a system state backup using Windows Server Backup.
To compact the Active Directory database, use the following procedure:
The commands used in this procedure require that you run them from an elevated Command Prompt. Open a command prompt as Administrator and run the following commands.
Stop the Active Directory Domain Service.
To perform an offline defragmentation, you must stop the Active Directory Domain Service (NTDS). Run the following command as an administrator and answer “Y” to accept stopping additional services.
net stop ntds
Run the NtdsUtil.exe commands
by running the following commands, you will compact the database and check the integrity of the database.
Activate instance NTDS
Compact to c:\
If the defragmentation completes successfully, copy the new database file to the c:\Windows\ NTDS directory and then delete the log files.
copy c:\ntds.dit c:\windows\NTDS\ntds.dit
Start the Active Directory Domain Service.
Once the tasks have finished, we will start the Active Directory Domain Service (NTDS) again. Run the following command as administrator.
net start ntds
If you want to know more about AD DS database compaction, check out this link: https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-r2-and-2008/cc794920(v%3dws.10)