Skip to content

PowerShell Script to Recycle Application Pools in IIS

Category
Windows
Covers
IIS
Versions & support
About Windows →
On this page

Maintaining the best performance and stability in web applications on Internet Information Services (IIS) is very important. One important task for managing IIS is recycling application pools. This helps improve reliability, reduce memory leaks, and ensure a smooth user experience.

In this article, we will show you how to create a PowerShell script to recycle all application pools in IIS automatically. This will save you time and allow you to schedule the recycling process during off-peak hours, minimizing any impact on your web applications’ performance.

Recycle All Application Pools in IIS (PowerShell)

To create a PowerShell script that recycles all application pools in IIS, follow these steps:

  1. Open a text editor and paste the following PowerShell code:
    
    Import-Module WebAdministration
    
    # Get all application pools
    $AppPools = Get-ChildItem IIS:\AppPools
    
    # Recycle each application pool
    foreach ($AppPool in $AppPools) {
        Write-Host "Recycling application pool: $($AppPool.Name)"
        $AppPool.Recycle()
    }
    
    Write-Host "All application pools have been recycled."
    
    
  2. Save the script with a .ps1 file extension, such as RecycleAppPools.ps1.
  3. Run the script by executing the following command in a PowerShell console with administrative privileges:
    
    .\RecycleAppPools.ps1
    
    

This script imports the WebAdministration module, retrieves all application pools in IIS, and recycles each of them. Note that you must have IIS and the WebAdministration module installed on your system to run this script.

Conclusion

In summary, we have shown you a PowerShell script that automates recycling all application pools in IIS, an important task in web server management. This script improves the reliability and performance of your web applications and saves time on manual server management. By scheduling the recycling process during off-peak hours, you can minimize any impact on the user experience. Automation is key to improving efficiency and reducing the risk of human error. With this PowerShell script, you are better equipped to manage your IIS server and ensure the best performance for your web applications.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top