/// <summary>
        /// List all properties of an IIS applicationpool
        /// </summary>
        /// <param name="serverName">Name of the IIS server e.g. localhost</param>
        /// <param name="appPoolName">Name of the applicationpool e.g. test</param>
        public void ListAppPoolProperties(string serverName, string appPoolName)
        {
            if (string.IsNullOrEmpty(serverName)) { throw new Exception("Parameter [serverName] can't be null or empty"); }
            if (string.IsNullOrEmpty(appPoolName)) { throw new Exception("Parameter [appPoolName] can't be null or empty"); }

            DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc/apppools", serverName));

            foreach (DirectoryEntry site in w3svc.Children)
            {
                Console.WriteLine("Applicationpool");
                foreach (PropertyValueCollection property in site.Properties)
                {
                    Console.WriteLine("Applicationpool Property");
                    Console.WriteLine(string.Format("{0}[{1}]", property.PropertyName, property.Value));
                }

                if (site.Properties["ServerComment"] != null)
                {
                    if (site.Properties["ServerComment"].Value != null)
                    {
                        if (string.Compare(site.Properties["ServerComment"].Value.ToString(), appPoolName, false) == 0)
                        {
                            foreach (DirectoryEntry child in site.Children)
                            {
                                Console.WriteLine("Applicationpool child");
                                foreach (PropertyValueCollection property in child.Properties)
                                {
                                    Console.WriteLine("Applicationpool child property");
                                    Console.WriteLine(string.Format("{0}[{1}]", property.PropertyName, property.Value));
                                }
                            }
                        }
                    }
                }
            }
        }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.