Home arrow Articles arrow HOW TO: Manually trigger the directory service garbage collection process
HOW TO: Manually trigger the directory service garbage collection process Print E-mail

There may be an occasion whereby you need to manually trigger the garbage collection process, as by default it runs every twelve hours. There aren’t going to be many occasions, but one such occasion might be that you want an immediate, up-to-date report on the size of the DIT and the amount of whitespace within the DIT.

Note. The DIT size and amount of whitespace aren’t logged by default. To enable this, please refer to the following msresource.net article:


To manually trigger, or invoke, the garbage collection process you modify the operational attribute doGarbageCollection. As with most (but not all) operational attributes, you set the value to 1.

Operational attributes are not defined in the schema, they are attributes that perform internal functions. You modify these attributes by using a null base DN. Such operations are sometimes referred to as RootDSE modifications.

Modifying doGarbageCollection via LDIF (using LDIFDE)

The following sample LDIF file will trigger Garbage Collection on the DC that you run this against.

    dn:
changeType: modify
replace: doGarbageCollection
doGarbageCollection: 1
-

To use this LDIF file, copy and paste the above text into a text file and save with an LDF file extension. Assuming you wish to target a DC called dc01 and the above LDIF was saved into a file called gbgCollection.ldf, the following command will trigger garbage collection.
    ldifde -i -f gbgCollection.ldf -s dc01

Modifying doGarbageCollection via command-line (using ADMOD)

The following command will modify doGarbageCollection using the freeware tool, ADMOD. Again, as an example we target the domain controller dc01.

    admod -b "" doGarbageCollection::1 - dc01

Modifying doGarbageCollection via .NET

The following is a C# method that runs garbage collection on the DC passed as dCHostname.
	public void RunGarbageCollection(string dCHostname) {
string bindStr = String.Format("LDAP://{0}/RootDSE", dCHostname);
DirectoryEntry dse = new DirectoryEntry(bindStr);
dse.Properties["doGarbageCollection"].Value = 1;
dse.CommitChanges();
}


Summary

To trigger garbage collections manually, you must modify the operational attribute doGarbageCollection with a value of 1. To modify an operational attribute you use a null (empty) base DN.

You can modify an operational attribute just like any other attribute. You simply have a blank DN as the base. If you’re using ADSI (or System.DirectoryServices) the base is RootDSE.

More information

For more information on Active Directory Garbage Collection and on-line defragmentation, please refer to the msresource.net knowledgebase article:


Document information

Author: Paul Williams
Written: 25-07-2007
Version: 1.0
Last updated: 25-07-2007
Last updated by: Paul Williams




Del.icio.us!Technorati!StumbleUpon!Furl!
 
< Prev   Next >