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.
2 Answers
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;
}
}
}
-
The problem with this is that it gets all the used application pools. I need all the avalible appolication pools.– dburnerCommented May 22, 2014 at 11:14
-
You mean all application pools that sharepoint sites are not using? Or somthing else?– AanchalCommented May 22, 2014 at 11:15
-
I need a list of all the application pools available to create a new Service Application. For example when you create a new service application you can select use existing application pool. I need all the pools from that combobox. The exact list that
Get-SPServiceApplicationPool
returns without any parameters.– dburnerCommented May 22, 2014 at 11:19
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
-
This dosent work. There are some pools that are displayed in Sharepoint but are not displayed in IIS (or using your code).– dburnerCommented May 22, 2014 at 12:12