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).
Hi,
I need a powershell script to to do iis reset which will get the list of servers from a json file, i should have option to do iisreset for component like WebbAPP , hostapi or all servers, and the script should reset a batch of 10 servers at a time parallelly also script should have capability to give me result whether any job failed and should be able to log the last reset time.
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
}
Thanks Faraz.
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…