How to Start/Stop IIS 7 Application Pool with Spaces in Name Using Command Line


1 views

When working with IIS 7 application pools that contain spaces in their names, you might encounter frustrating errors when attempting to manage them through the command line. The standard appcmd approach fails because:

C:\Windows>appcmd stop apppool /apppool.name: My App Services
Failed to process input: The parameter 'App' must begin with a / or - (HRESULT=80070057)

Even when trying to use quotes around the name:

C:\Windows>appcmd stop apppool /apppool.name: "My App Services"
ERROR ( message:The attribute "apppool.name" is not supported in the current command usage. )

The solution is to properly escape the application pool name using double quotes in a specific way. Here's the correct syntax:

appcmd stop apppool /apppool.name:"My App Services"

Notice that the quotes are inside the attribute specification, not outside. This applies to both stopping and starting application pools:

appcmd start apppool /apppool.name:"My App Services"

For more robust management, consider using PowerShell instead of appcmd:

Import-Module WebAdministration
Stop-WebAppPool -Name "My App Services"
Start-WebAppPool -Name "My App Services"
Restart-WebAppPool -Name "My App Services"

If you need to incorporate this into batch scripts, here's a reliable template:

@echo off
set APP_POOL_NAME="My App Services"
%SystemRoot%\System32\inetsrv\appcmd stop apppool /apppool.name:%APP_POOL_NAME%
timeout /t 5
%SystemRoot%\System32\inetsrv\appcmd start apppool /apppool.name:%APP_POOL_NAME%

Error: "The attribute apppool.name is not supported"
Solution: Ensure the quotes are immediately after the colon with no space:

appcmd stop apppool /apppool.name:"My App Services"  // Correct
appcmd stop apppool /apppool.name: "My App Services" // Incorrect

To recycle all application pools containing spaces in their names:

for /f "tokens=*" %%a in ('appcmd list apppools /text:name') do (
    if not "%%~a"=="DefaultAppPool" (
        echo Recycling %%a
        appcmd recycle apppool /apppool.name:"%%a"
    )
)

When managing IIS 7 application pools via the command line, spaces in the app pool name can cause syntax errors. The standard appcmd approach fails because:

  • Unquoted names with spaces break command parsing
  • Quoted names trigger attribute validation errors

For app pools containing spaces, use this format:

appcmd stop apppool /apppool.name:"My App Services"

Key points:

  • Place quotes inside the parameter value
  • No space after the colon
  • Case-sensitive matching of the app pool name

Using PowerShell

Import-Module WebAdministration
Stop-WebAppPool -Name "My App Services"

Via WMI

wmic service where "name='W3SVC'" call startservice
wmic service where "name='W3SVC'" call stopservice

If commands still fail:

  1. Verify app pool exists: appcmd list apppool
  2. Check IIS worker process status
  3. Run command prompt as Administrator

Here's a complete batch script example:

@echo off
SET APP_POOL_NAME="My App Services"

:: Stop the pool
C:\Windows\System32\inetsrv\appcmd stop apppool /apppool.name:%APP_POOL_NAME%

:: Wait 5 seconds
timeout /t 5

:: Start the pool
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:%APP_POOL_NAME%