Skip to content

How to List All IIS Application Pools in Batch Script

Learn how to enumerate and display all IIS application pools using Batch Script with appcmd.exe, including basic listings, detailed configuration exports, and CSV inventory generation.

Application pools are the process-level containers that host IIS web applications. Each pool runs as an independent w3wp.exe worker process, and understanding which pools exist, their runtime configuration, and their current state is essential for server auditing, capacity planning, and troubleshooting. Listing all pools from a Batch Script provides instant visibility without navigating through the IIS Manager GUI.

In this guide, we will explore how to enumerate and display all IIS application pools using the appcmd.exe command-line tool, from simple listings to detailed configuration exports.

Method 1: Basic Application Pool Listing

@echo off
setlocal

set "appcmd=%SystemRoot%\System32\inetsrv\appcmd.exe"

:: Verify Admin
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Administrator privileges required.
    pause
    exit /b 1
)

:: Verify appcmd exists
if not exist "%appcmd%" (
    echo [ERROR] appcmd.exe not found at: %appcmd%
    echo         IIS may not be installed or Management Tools are missing.
    pause
    exit /b 1
)

echo =============================================
echo       IIS APPLICATION POOLS
echo =============================================
echo.

"%appcmd%" list apppool

if %errorlevel% neq 0 (
    echo.
    echo [WARNING] Could not retrieve pool list. The IIS service may not be running.
)

echo.
pause

Sample Output

APPPOOL "DefaultAppPool" (MgdVersion:v4.0,MgdMode:Integrated,state:Started)
APPPOOL "CompanyApiPool" (MgdVersion:v4.0,MgdMode:Integrated,state:Started)
APPPOOL ".NET v4.5 Classic" (MgdVersion:v4.0,MgdMode:Classic,state:Started)
APPPOOL "LegacyPool" (MgdVersion:v2.0,MgdMode:Classic,state:Stopped)

Each line shows the pool name, managed runtime version, pipeline mode, and current state.

Method 2: Listing Only Pool Names

For scripts that need a clean list of pool names without metadata:

@echo off
setlocal enabledelayedexpansion

set "appcmd=%SystemRoot%\System32\inetsrv\appcmd.exe"

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

if not exist "%appcmd%" (
    echo [ERROR] appcmd.exe not found. IIS may not be installed.
    pause
    exit /b 1
)

echo Application Pool Names:
echo =======================

set "count=0"
for /f "delims=" %%P in ('"%appcmd%" list apppool /text:name 2^>nul') do (
    set /a "count+=1"
    echo   !count!. %%P
)

if !count! equ 0 (
    echo   [No application pools found]
)

echo.
echo Total: !count! pools
pause

Method 3: Detailed Configuration Report

For each pool, this script queries and displays its runtime version, pipeline mode, identity, state, and associated websites.

@echo off
setlocal enabledelayedexpansion

set "appcmd=%SystemRoot%\System32\inetsrv\appcmd.exe"

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

if not exist "%appcmd%" (
    echo [ERROR] appcmd.exe not found. IIS may not be installed.
    pause
    exit /b 1
)

echo.
echo =============================================
echo   DETAILED APPLICATION POOL REPORT
echo =============================================

set "pool_count=0"

for /f "delims=" %%N in ('"%appcmd%" list apppool /text:name 2^>nul') do (
    set /a "pool_count+=1"
    set "name=%%N"
    echo.
    echo --- !name! ---

    :: State
    for /f "delims=" %%S in ('"%appcmd%" list apppool /name:"!name!" /text:state 2^>nul') do echo   State:          %%S

    :: .NET Version
    set "ver="
    for /f "delims=" %%V in ('"%appcmd%" list apppool /name:"!name!" /text:managedRuntimeVersion 2^>nul') do set "ver=%%V"
    if defined ver (
        echo   .NET Version:   !ver!
    ) else (
        echo   .NET Version:   No Managed Code
    )

    :: Pipeline Mode
    for /f "delims=" %%M in ('"%appcmd%" list apppool /name:"!name!" /text:managedPipelineMode 2^>nul') do echo   Pipeline:       %%M

    :: Identity
    for /f "delims=" %%I in ('"%appcmd%" list apppool /name:"!name!" /text:processModel.identityType 2^>nul') do echo   Identity:       %%I

    :: Associated Websites
    set "sites_found=0"
    for /f "delims=" %%A in ('"%appcmd%" list app /apppool.name:"!name!" /text:site.name 2^>nul') do (
        if !sites_found! equ 0 (
            echo   Sites:          %%A
        ) else (
            echo                   %%A
        )
        set /a "sites_found+=1"
    )
    if !sites_found! equ 0 echo   Sites:          ^(none^)

    :: Worker Process PID (if running)
    set "wp_found=0"
    for /f "delims=" %%W in ('"%appcmd%" list wp /apppool.name:"!name!" 2^>nul') do (
        echo   Worker:         %%W
        set "wp_found=1"
    )
)

echo.
echo =============================================
echo  Total: !pool_count! application pools
echo =============================================
pause

Method 4: Status Dashboard with Running/Stopped Counts

@echo off
setlocal enabledelayedexpansion

set "appcmd=%SystemRoot%\System32\inetsrv\appcmd.exe"

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

if not exist "%appcmd%" (
    echo [ERROR] appcmd.exe not found. IIS may not be installed.
    pause
    exit /b 1
)

:dashboard
cls
echo =============================================
echo   APPLICATION POOL STATUS
echo   %COMPUTERNAME% - %date% %time:~0,8%
echo =============================================
echo.

set "running=0"
set "stopped=0"
set "total=0"

for /f "delims=" %%N in ('"%appcmd%" list apppool /text:name 2^>nul') do (
    set /a "total+=1"
    set "name=%%N"
    set "state=Unknown"
    for /f "delims=" %%S in ('"%appcmd%" list apppool /name:"!name!" /text:state 2^>nul') do set "state=%%S"

    if /i "!state!"=="Started" (
        echo   [*] !name!
        set /a "running+=1"
    ) else (
        echo   [ ] !name!  ^(!state!^)
        set /a "stopped+=1"
    )
)

if !total! equ 0 (
    echo   [No application pools configured]
)

echo.
echo ---------------------------------------------
echo  Running: !running!  Stopped: !stopped!  Total: !total!
echo ---------------------------------------------
echo.
echo Press any key to refresh, or Ctrl+C to exit.
pause >nul
goto :dashboard

Method 5: CSV Export for Inventory

@echo off
setlocal enabledelayedexpansion

set "appcmd=%SystemRoot%\System32\inetsrv\appcmd.exe"
set "output=%~dp0iis_pools_%COMPUTERNAME%.csv"

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

if not exist "%appcmd%" (
    echo [ERROR] appcmd.exe not found. IIS may not be installed.
    pause
    exit /b 1
)

echo Exporting application pools to CSV...

:: Header
> "%output%" echo PoolName,State,RuntimeVersion,PipelineMode,Identity

set "count=0"

:: Data rows
for /f "delims=" %%N in ('"%appcmd%" list apppool /text:name 2^>nul') do (
    set /a "count+=1"
    set "name=%%N"

    set "state="
    set "ver="
    set "mode="
    set "ident="

    for /f "delims=" %%S in ('"%appcmd%" list apppool /name:"!name!" /text:state 2^>nul') do set "state=%%S"
    for /f "delims=" %%V in ('"%appcmd%" list apppool /name:"!name!" /text:managedRuntimeVersion 2^>nul') do set "ver=%%V"
    for /f "delims=" %%M in ('"%appcmd%" list apppool /name:"!name!" /text:managedPipelineMode 2^>nul') do set "mode=%%M"
    for /f "delims=" %%I in ('"%appcmd%" list apppool /name:"!name!" /text:processModel.identityType 2^>nul') do set "ident=%%I"

    if not defined ver set "ver=None"

    >> "%output%" echo !name!,!state!,!ver!,!mode!,!ident!
)

echo.
echo [SUCCESS] Exported !count! pools to: %output%
echo.
type "%output%"
echo.
pause

Using PowerShell for Advanced Queries

For rich formatting and filtering capabilities:

@echo off
setlocal

:: Check for administrator privileges
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo [ERROR] Please run this script as ADMINISTRATOR.
    pause
    exit /b
)

echo IIS Application Pools (via PowerShell):
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command "& { if (Get-Module -ListAvailable -Name WebAdministration) { Import-Module WebAdministration; Get-ChildItem IIS:\AppPools | Format-Table Name, State, ManagedRuntimeVersion, ManagedPipelineMode -AutoSize } else { Write-Host '[ERROR] WebAdministration module not available.' -ForegroundColor Red; Write-Host 'Install the IIS Management Scripts and Tools feature.' } }"

echo.
pause

Common Mistakes

The Wrong Way: Using WMIC for Application Pools

:: WRONG - No standard WMI class for IIS app pools on IIS 7+
wmic /namespace:\\root\microsoftiisv2 path IIsApplicationPoolSetting

The Wrong Way: Parsing applicationHost.config

:: WRONG - Fragile and hard to maintain
findstr "application pool" "%SystemRoot%\System32\inetsrv\config\applicationHost.config"

The raw XML config file is complex, and findstr is not an XML parser. The string "application pool" may appear in comments, attribute values, or across line breaks, producing misleading results. Use appcmd which properly interprets the configuration and presents it in a parseable format.

The Wrong Way: Using delims=^"" to Extract Pool Names

:: WRONG - Fragile parsing that depends on output format
for /f "tokens=2 delims=^"" %%P in ('"%appcmd%" list apppool /text:name') do (
    echo %%P
)

Best Practices

  1. Use appcmd list apppool: The official, version-stable command for pool enumeration.
  2. Use /text:name with for /f "delims=": The /text:name flag returns one clean pool name per line without metadata. Use for /f "delims=" to capture names including spaces, rather than parsing the default output format with fragile delimiter tricks.
  3. Cross-reference with sites: Always show which websites are assigned to each pool so administrators can assess the impact of pool changes.
  4. Monitor worker PIDs: Listing worker processes (appcmd list wp) alongside pools reveals which pools are actively servicing requests vs. sitting idle.
  5. Initialize variables inside loops: Always set "var=" before sub-queries inside iteration blocks to prevent stale values from a previous iteration carrying over when a query produces no output.
  6. Verify appcmd.exe exists: Check for the tool at the start of every script to provide a clear error message on systems where IIS is not installed.
  7. Add 2>nul to sub-queries: Suppress stderr on appcmd sub-queries that may produce error output for pools with no associated applications or workers.

Conclusion

Listing all IIS application pools from a Batch Script is accomplished through the appcmd list apppool command. By enriching the basic listing with detailed property queries (runtime version, pipeline mode, identity, and associated websites), administrators gain a complete operational view of the IIS process architecture. Exporting this data to CSV creates a persistent inventory record, while real-time dashboards provide immediate visibility into pool health across the server.

Navigation