PoweShell script to perform IISReset across all servers in SharePoint Farm

Get all Servers in the Farm with the role not like invalid, get IIS application pool status if any app pool found stopped then restarts the same
and finally returns the status of Application pool.

asnp "*sh*"

$servers = Get-SPServer | ?{$_.Role -ne "Invalid"}


foreach ($server in $servers)
  {
    $servername = $server.Address
    Write-Host "Application Pool Status in : $server" -f Yellow
   
  Invoke-Command -ComputerName $servername -ScriptBlock {

   Import-Module WebAdministration

  IISRESET /noforce

  IISRESET /Status
 
    cd IIS:\

   $apppool =  gci .\AppPools

   try
   {
 
   $apppool | ?{$_.state -eq "stopped" } | Start-WebAppPool
    sleep 2;  
   }

   catch
   {
       Write-Error $_;
   }

   finally
   {
      $apppool | select Name, State | Format-Table
   
      Write-Host;
   }


   } #End of Scriptblock

 }


Comments

Popular posts from this blog

[Solved ] ...The product key entered does not match any of the Windows images available for installation. Enter a different product key

SharePoint Search Service application content sources showing Paused

User Profile Synchronization Service Struck on "Starting" - Fixed