Start, Stop and Restart IIS from a Remote PC

Exporting & Importing App Pools and Websites configuration between multiple IIS instances

Introduction

One of the most common SysAdmin requirements when operating on a Server Farm is being able to remotely start, stop and restart an instance of IIS from a different node on the same network, maybe before issuing a backup task or a similar cron job.

The best way to achieve such result is using PowerShell commands: before you can do that, you need to set either the node you’ll use to issue the command – we’ll call it the Source PC – and the node hosting the IIS instance you want to manage – we’ll call it the Target PC – as Trusted Hosts between each other: let’s see how to do that.

Setup the TrustedHosts

From the Source PC, open a Command Prompt with administrative priviledges and then go to PowerShell by typing   : once there, insert the following command – replacing the TARGET-HOST sample hostname  with the hostname or IP Address of the Target PC.

Do the same thing on your Target PC, replacing again the SOURCE-HOST sample hostname with the hostname or IP Address of the source PC:

As soon as you do that, you can run any PowerShell command between the two nodes which will be delivered via TCP. If you don’t do that, you’ll most likely incur in the following error message:

 

List of PowerShell Commands

Here are the relevant PowerShell command to issue, respectively, STOP, START and RESTART on the IIS instance installed on the target PC:

You can execute these command either from a PowerShell console or, if you prefer, from an elevated Command Prompt by adding a    at the start of each line. Again, remember to replace the TARGET-HOST sample hostname with the hostname or IP Address of the target PC.

You can also insert these commands in one or more PowerShell scripts (.ps1), which you can then launch from any other script: the choice is yours, depending on which script and or task you need to execute.

I hope that you’ll find these infromation useful enough: that said, happy remote restarting!

 

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

1 Comment on “Start, Stop and Restart IIS from a Remote PC”

  1. Hi Ryan,

    I am new to Powershell and quickly wanted to understand what is this command “winrm set winrm/config/client ‘@{TrustedHosts=”TARGET-HOST”}'” used for?

    In the invoke commands for start, stop & reset iis, where do we have to mention the specific website/webapppool name if we have multiple webite/webapppools.

    Thank you.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.