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
}
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
Post a Comment