In this article we can explore the following code:
- Retrieve Name & Type of all Servers in the Farm
Farm
A SharePoint Farm consists of multiple servers with roles associated with each. For example a typical 500 user Farm can contain:
- Web Front End Server
- Application Server
- Database Server
- Email Server
- Searcy Index Server
The following is a typical output from a Server Farm.
Code
Here we are using the Server Object Model code to retrieve the farm information.
For getting a Farm instance, we can use the SPFarm.Local property.
using Microsoft.SharePoint.Administration;
SPFarm farm = SPFarm.Local;
For iterating through the servers, we can use the Servers property of the Farm object.
foreach (SPServer server in farm.Servers)
{
}
For retrieving the Name, Role and Type we can use the instance properties of SPServer.
-
server.Name
-
server.Role
-
server.TypeName
The following is the console application code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace EnumFarmServers
{
class Program
{



Vijay SPosted Apr 7, 2015, 5:58 AM
Informative