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  powershell : 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  powershell  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

6 Comments 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.

  2. I never was able to get the following to run:
    invoke-command -computername “TARGET-HOST” -scriptblock {iisreset /STOP}

    Instead, this is the option that worked for me:
    iisreset /stop

    1. I enclosed the server name in “less than” and “greater than” brackets which were then stripped out of my comment. Let me see if I can get this comment to appear peroperly. What worked for me was:
      iisreset [remote-computer-name] /stop

      1. Are you sure you’re using it with PowerShell (and not command prompt), right? Because I use that command all the time and it definitely DOES work. However, I’m glad you found out another way to do that!

  3. Thanks for this Article it was very HelpFull. i Ran PowerShell with different User (Shift + Right Click) because my network user did not have access to remote IIS. Regards

  4. How can I do this if the target server is behind the firewall/on testnet?

    I am getting this and I think it’s because my host machine where I am running the commands is “production” and the target is “Testnet” :
    Connecting to remote server SERVERNAME failed with the following
    error message : WinRM cannot process the request. The following error occurred while using Kerberos authentication:
    Cannot find the computer SERVERNAME. Verify that the computer exists on the network and that the
    name provided is spelled correctly. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo : OpenError: (SERVERNAME:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken

    I tried with IP addresses instead of hostnames and got this:
    Connecting to remote server IPADDRESS failed with the following error message : The WinRM client
    cannot process the request. Default authentication may be used with an IP address under the following conditions: the
    transport is HTTPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Use
    winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated.

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.

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