How To Install IIS, Create Application Pool And Using PowerShell Script How To Start And Stop IIS App Pool

Hello friends, in this article, I will show how we can install IIS, create an Application Pool, and use PowerShell commands to start and stop the application pool.

Check if IIS is installed or not

Go to Control Panel=> All Control Panel Items => Programs and Features and click on Turn windows features on or off.

Start And Stop IIS App Pool

Make sure Internet Information services are installed on the machine [for which you want to run the power shell script to start/stop application pool].

If it is not installed check the Internet Information Services check box and click install.

As we can see IIS is installed already,

Start And Stop IIS App Pool

Open IIS

To Open IIS on run window type -> inetmgr and press ok,

Start And Stop IIS App Pool

This will open IIS and we can see Application Pools on the right side pane as below,

Start And Stop IIS App Pool

Create app pool

When you add any website on IIS then the app pool is automatically created for the website with the same name as the website OR we can create application pool manually as shown,

Start And Stop IIS App Pool

I created an ASP.NET web forms site and hosted the website on IIS,

Start And Stop IIS App Pool

An App pool created with the name DemoPowerShell as shown,

Start And Stop IIS App Pool

When IIS is installed, it comes with a PowerShell module called WebAdministration. This module gives you many different cmdlets for managing IIS.

Powershell Get-Command

If you run the below command using PowerShell,


Start And Stop IIS App Pool

You can see we've got six cmdlets specifically dedicated to managing webAppPool.

Start And Stop IIS App Pool

Note

Ps1 is the extension for power shell file.

Now, we are going to use Start-WebAppPool and Stop-WebAppPool cmdlet in this article.


Stop-WebAppPool

Invoke-command
The command is used to run commands on local and remote computers. We have to specify the parameters as computerName, credentials, and inside the script block, write the cmdlet.

To learn more about Invoke-command, read MSDN link here

We can use invoke-command as shown,

Start And Stop IIS App Pool

Write the below command and use variables to define the UID, Password and computer name [on which you want the PowerShell script to stop the Application Pool] and click on run script button,

Start And Stop IIS App Pool

A script is running as we see the stop button as red,

Start And Stop IIS App Pool

Now, the command is completed successfully,

Start And Stop IIS App Pool

Go to IIS and check the status of DemoPowerShell app pool, it's stopped as shown,

Start And Stop IIS App Pool

Start-WebAppPool

Write the Start-WebappPool in the script block as shown and run the script.


Start And Stop IIS App Pool

Go to IIS and check the app pool has started as expected.

Start And Stop IIS App Pool

Summary

We already saw the cmdlet for,
  • Start-WebAppPool
  • Stop-WebAppPool

Try another cmdlet at your end to get an idea of how it works.

Start And Stop IIS App Pool

NOTE

I'll use this article in my release definition using TFS 2015 as a Powershell Task. Keep reading.


Similar Articles