Posts

Showing posts with the label SharePoint Farm

SharePoint Server - Recycle / Stop-Start Application/Site pool using C#

Image
As a continuation of my previous post List All Servers in SharePoint Farm using C# Now w'll see to Start/Stop Pools without login to the server each time. { Please check the NOTE at the very end on this post } List All Application/Site Pools /// <summary> /// Load Pools from the given server /// </summary> /// <param name="serverName">Server name</param> /// <param name="pool">Pool type</param> public void LoadPools( string serverName, PoolType pool) { var server = ServerManager.OpenRemote(serverInstance); if (pool == PoolType.AppPool) { appPoolCollection = new List<ApplicationPool>(); appPoolCollection = server.ApplicationPools.ToList(); } else if (pool == PoolType.SitePool) { siteCollection = new List<Site>(); siteCollection = server.Sites.ToList(); } } Start/Stop Application Pool /// <summary> /// Reset Applicat

List All Servers in SharePoint Farm - C#

Image
Some times we need to login to all the servers in SharePoint farm just to restart selected Application or Site Pool. Let's see a C# code how to retrieve and recycle selected pools from all the servers in our SharePoint farm. In this series will see How to retrieve all servers in SharePoint farm using C# PS: Please check the NOTE at the very end on this post. First things first import dll's using System ; using Microsoft.SharePoint ; using Microsoft.SharePoint.Administration ; using Microsoft.Web.Administration ; Declare global variables // Global enum Variables public enum Action { Start, Stop, Invalid } ; public enum PoolType { AppPool, SitePool } ; // Global Server variable public List<string> servers = null ; // Global Pool ' s collection variables public List<ApplicationPool> appPoolCollection = null ; public List<Site> siteCollection = null ; Get All SharePoint Farm server names public