I totally didn’t know that there was a ManagementObjectEnumerator class, but I found out there was today which made me all sorts of happy. What I was trying to do was to just display a list of the application pools of the current host machine’s IIS instance within this small WinForms app I have that performs some warm-up functions for SharePoint. I needed to target application pools because we have a complex recycling theme, and I needed scheduled post-warm up functions. What I ended up doing in order to list them was just this:
string l_strClassPath = @”\\” + hostname + @”\root\microsoftiisv2:IIsApplicationPoolSetting”;
using (ManagementClass l_oWmi = new ManagementClass(l_strClassPath))
using (ManagementObjectCollection.ManagementObjectEnumerator l_oMoEnumerator = l_oWmi.GetInstances().GetEnumerator())
ManagementObject l_oChildMO = ((ManagementObject)l_oMoEnumerator.Current);
char l_aSplitChar = “/”.ToCharArray();
tbApplicationPoolList.Items.Add(l_oChildMO.ToString().Split(l_aSplitChar)[(l_oChildMO.ToString().Split(l_aSplitChar).Length – 1)].Replace(“\””, “”));
I like that!