Restart IIS service Remotely On A Number Of Servers

I was at a customer site and was asked whether there was an easy way to restart IIS service remotely on a number of servers. Yes, with the help of PowerShell. Run the following to do an iisreset on a number of servers. Invoke-Command –ComputerName server1,server2, server3 –ScriptBlock { iisreset /noforce } If you want…

I was at a customer site and was asked whether there was an easy way to restart IIS service remotely on a number of servers.

Yes, with the help of PowerShell. Run the following to do an iisreset on a number of servers.

Invoke-Command –ComputerName server1,server2, server3 –ScriptBlock { iisreset /noforce }

If you want to use another account which has admin rights, run

$cred = Get-Credential

Invoke-Command –ComputerName server1,server2, server3 –ScriptBlock { iisreset /noforce } –Credential $cred

You can also use iisreset.exe /restart in the script block. If you have a list of server names in a text file, you can use that with the invoke-command. Run

Invoke-Command –ComputerName (Get-Content C:\servers.txt) –ScriptBlock { iisreset /noforce }

This will only work on servers which has PowerShell 2.0. Another option will be to use PsExec (PsTools).

3 Comments

  1. You can put list of servers in a txt file and then import in ps

    $cred = Get-Credential
    $servers = gc “E:\Deployment\iis2.txt”
    foreach ($server in $servers)
    {
    Write-Host “Resting IIS on $server”
    Invoke-Command –ComputerName $server –ScriptBlock { iisreset /noforce } -Credential $cred
    }

    1. Rajith Enchiparambil says:

      Thanks Faraz.

  2. is there any way that we can get the Server names and the output in a Table format…

    nvoke-Command –ComputerName server1,server2, server3 –ScriptBlock { iisreset /noforce } | ft

    Doesnt help…

Leave a Reply

Your email address will not be published. Required fields are marked *