Skip to main content

Microsoft Exchange Server depends on Internet Information Services (IIS). Sometimes you have to restart IIS, which you can do through IIS management or the console (Command Prompt or PowerShell). But what if you have more than multiple Exchange Servers running, and you have to restart IIS on all of them? In this article, you will learn how to restart the IIS service remotely on all Exchange Servers with PowerShell.

Restart IIS Exchange Server PowerShell script

The Restart-ExchangeIIS.ps1 PowerShell script will get all the Exchange Servers. After that, it will restart IIS on the Exchange Servers and show the IIS status.

Note: The Restart-ExchangeIIS.ps1 PowerShell script must be run on a Management Server or Exchange Server because you need the Exchange Management tools installed.

Prepare restart Exchange Server IIS PowerShell script

Download the script Restart-ExchangeIIS.ps1 or copy and paste the below code in Notepad. Give it the name Restart-ExchangeIIS.ps1 and place it in the C:\scripts folder. Create a scripts folder if you don’t have one.

Ensure the file is unblocked to prevent errors when running the script. .

# Load Exchange Management Shell PowerShell Snap-In
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

# Get All Exchange Servers
$Servers = Get-ExchangeServer

# Go through the list and restart one by one
foreach ($Server in $Servers) { 
    Write-Host "Restarting IIS on server: $($Server.Name)" -ForegroundColor Green
    IISRESET $Server.Name

    # Optional: Get the Status
    Write-Host "IIS status for server $($server):" 
    IISRESET $server.Name /status
Write-host "IIS restarted on all Exchange Servers." -ForegroundColor Green

It will look like this.

Restart IIS on all Exchange Servers with PowerShell scripts folder

Run restart Exchange Server IIS PowerShell script

Run Exchange Management Shell as administrator. Change the path to the scripts folder. Run the PowerShell script to restart IIS on all Exchange Servers. Wait till it completes.

[PS] C:\>cd C:\scripts

[PS] C:\scripts>.\Restart-ExchangeIIS.ps1

The below screen shows how it looks when running the script in an organization with two Exchange Servers (EX01-2019/EX02-2019) running in the organization.

Restart IIS on all Exchange Servers with PowerShell script running

Did this help you to restart IIS on the Exchange Servers?

Leave a Reply