Listing available Properties of an DirectoryEntry object

If you are messing with IIS in C# code, you can do quite a bit if you System.DirectoryServices and the DirectoryEntry object. This can be extended if you know the name of the items in a the DirectoryEntry’s property collection. You can get these as follows:

using System;
using System.Collections.Generic;
using System.DirectoryServices;

namespace FindIISLogWithCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> AvailableProperties = new List<string>();
            DirectoryEntry folderRoot = new DirectoryEntry("IIS://localhost/W3SVC");
            PropertyCollection pc = folderRoot.Properties;
            foreach (PropertyValueCollection p in pc)
            {
                AvailableProperties.Add(p.PropertyName);                
            }
            
            // Sort alphabetically
            AvailableProperties.Sort();                       
            foreach (String prop in AvailableProperties)
            {
                Console.WriteLine(prop);
            }
        }
    }
}

Of course, different DirectoryEntry objects can have different lists. However, this exact one created the following list on a Windows 2008 R2 64-bit Server with IIS installed and configured.

AccessFlags
AccessSSLFlags
AnonymousUserName
ApplicationDependencies
AppPoolId
AspDiskTemplateCacheDirectory
AuthFlags
DefaultDoc
DirBrowseFlags
DontLog
HttpCustomHeaders
HttpErrors
IIs5IsolationModeEnabled
KeyType
LogFileDirectory
LogPluginClsid
NTAuthenticationProviders
RedirectHeaders
ScriptMaps
SSIExecDisable
SslUseDsMapper
TraceUriPrefix
WebSvcExtRestrictionList

Leave a Reply

How to post code in comments?