Blog

Script: Perform IISRESET on entire SharePoint farm


by Tobias Lekman, 05 December, 2016

This short utility script can be used to restart IIS on all servers in a farm without specifying machine names.

function Reset-Servers {
    Write-Host "`tPerforming IISRESET on farm" -tabs 1
    $servers = Get-SPServer | Where-Object { $_.Role -eq "Application" }
    foreach ($server in $servers) {
        Write-Host ("`t`tReset " + $server.Address + "...") -NoNewLine
        $success = $false
        $out = IISRESET $server.Address
        $out | ForEach-Object { if ($_.Contains("success")) { $success = $true } }
        if ($success) {
            Write-Host " Done" -ForegroundColor Green
        } else {
            Write-Host " Failed. Perform manual reset." -ForegroundColor Red
        }
    }
}

The last check verifies that the RPC call went thourgh successfully.