Question

How to I get a list of all SPIisWebServiceApplicationPool on my current farm? There is a powershell command that can do this named Get-SPServiceApplicationPool but I want to get the list in a C# application without using a PowerShell object.

Was it helpful?

Solution

Try following: You can modify according to your need and name any service which is by default present in Each webaplication.

foreach (SPService service in SPFarm.Local.Services)
{
    if (service.Name.Equals("ServiceName"))
    {
        foreach (SPServiceApplication serviceApp in service.Applications)
        {
            SPIisWebServiceApplication webServiceApp = (SPIisWebServiceApplication) serviceApp;
            SPIisWebServiceApplicationPool appPool = webServiceApp.ApplicationPool;
        }
    }
}

OTHER TIPS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;

namespace AppPoolEnum
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryEntries appPools = 
                new DirectoryEntry("IIS://localhost/W3SVC/AppPools").Children;

            foreach (DirectoryEntry appPool in appPools)
            {
                Console.WriteLine(appPool.Name);
            }
        }
    }
}

Source: https://stackoverflow.com/questions/1400464/enumerating-application-pools-in-iis

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top