Tuesday, February 25, 2014

Start all the application pools which are stopped in the SharePoint 2010 Farm (Using PowerShell)

# Start the application pools stopped in the SharePoint 2010 farm
function StartStoppedAppPools
{
   
    foreach ($server in (Get-SPServer | Where {$_.Role -ne "Invalid"}) )
    {
        $apppool = Get-WmiObject -Namespace root\MicrosoftIISv2 -Class IIsApplicationPoolSetting -ComputerName $server.name -Authentication 6 | Where { $_.AppPoolState -eq '4'} | select name
        if ($apppool -eq $null) {
            Write-Host "No app pools are stopped on server $($server.Name)" -foregroundcolor green
            continue
        }
        else
        { 
         foreach ($appObj in $apppool)
             {
        $app = $appObj | Out-String
           $apppoolname = $app.Substring($app.LastIndexOf('/') + 1,($app.Length-$app.LastIndexOf('/'))-1).Trim()
             
              if($apppoolname -eq 'SharePoint Web Services Root')
              {
                 Write-Host "App Pool $apppoolname does not require to start in $($server.Name)" -foregroundcolor yellow           
              }
              else{
            Write-Host "Starting the app pool '$($apppoolname)'"
            Get-WmiObject -Namespace 'root\webadministration' -Class ApplicationPool -ComputerName $server.name -Authentication 6 -Filter "Name='$apppoolname'" | Invoke-WmiMethod -Name Start
             
                  Write-Host "App Pool $apppoolname is started on server $($server.Name)" -foregroundcolor green
                 }
             }
        }
    }  
}

Example

No comments:

Post a Comment