Reputation: 255
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
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