Ramalingam
Ramalingam

Reputation: 255

How to get front end servers from sharepoint 2010 farm

I have an requirement of getting the front end web server in SharePoint farm.This is the code for getting it.

SPFarm myFarm = SPFarm.Local;
SPServerCollection serverColl = myFarm.Servers;
if (serverColl != null && serverColl.Count > 0)
{
foreach (SPServer spserver in serverColl)
{
  //get exceute
}
}

May I know this the appropriate way to achieve this or any other suitable way to achieve it ?

Upvotes: 2

Views: 3295

Answers (1)

Patrick Pitre
Patrick Pitre

Reputation: 851

What are you asking, exactly? You're like 95% of the way there. On the spserver variable, just call the Role and/or Name properties, as such:

    foreach (SPServer spserver in serverColl)
    {
       spserver.Role // will be WebFrontEnd, Application, etc.
    }

See here for the possible values of the SPServerRole enumeration.

Upvotes: 3

Related Questions