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.
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,
Open IIS
To Open IIS on run window type -> inetmgr and press ok,
This will open IIS and we can see Application Pools on the right side pane as below,
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,
I created an ASP.NET web forms site and hosted the website on IIS,
An App pool created with the name DemoPowerShell as shown,
When IIS is installed, it comes with a PowerShell module called WebAdministration. This module gives you many different cmdlets for managing IIS.
Powershell Get-CommandIf you run the below command using PowerShell,
You can see we've got six cmdlets specifically dedicated to managing webAppPool.
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,
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,
A script is running as we see the stop button as red,
Now, the command is completed successfully,
Go to IIS and check the status of DemoPowerShell app pool, it's stopped as shown,
Start-WebAppPoolWrite the Start-WebappPool in the script block as shown and run the script.
Go to IIS and check the app pool has started as expected.
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.
NOTE
I'll use this article in my release definition using TFS 2015 as a Powershell Task. Keep reading.