Share via


Cool Things You Can Do with AppCMD in IIS 7

If you haven't had a chance yet to mess around with IIS 7, you should take the time. One of the changes that will impact everyone is configuration. Not only have we changed where configuration settings are stored, but we've also released a very cool command-line tool for examining and changing configuration called appcmd.exe. However, appcmd.exe is not just about configuration. There are some really cool things that you can do with it.

 

Wildcard Mapping

You can use wildcard characters with appcmd using the following syntax:

appcmd list apppool /name:"$=*2007"

This command will list all application pools with a name ending in "2007". Using a variation on the same method, you can find all application pools running under the identify of users in a particular domain.

appcmd list apppool /processModel.userName:"$=MyDomain\*"

This will list all application pools with running with an identity of users in the "MyDomain" domain.

Tip: You can find out all of the attributes that can be used with appcmd by querying for help after using an attribute. For example:

appcmd list apppools /name:DefaultAppPool -?

ERROR ( message:-name
-queueLength
-autoStart
-enable32BitAppOnWin64
-managedRuntimeVersion
-enableConfigurationOverride
-managedPipelineMode
-passAnonymousToken
-processModel.identityType
-processModel.userName
-processModel.password
-processModel.loadUserProfile
-processModel.manualGroupMembership
-processModel.idleTimeout
-processModel.maxProcesses
-processModel.shutdownTimeLimit
-processModel.startupTimeLimit
-processModel.pingingEnabled
-processModel.pingInterval
-processModel.pingResponseTime
-recycling.disallowOverlappingRotation
-recycling.disallowRotationOnConfigChange
-recycling.logEventOnRecycle
-recycling.periodicRestart.memory
-recycling.periodicRestart.privateMemory
-recycling.periodicRestart.requests
-recycling.periodicRestart.time
-recycling.periodicRestart.schedule.[value='timespan'].value
-failure.loadBalancerCapabilities
-failure.orphanWorkerProcess
-failure.orphanActionExe
-failure.orphanActionParams
-failure.rapidFailProtection
-failure.rapidFailProtectionInterval
-failure.rapidFailProtectionMaxCrashes
-failure.autoShutdownExe
-failure.autoShutdownParams
-cpu.limit
-cpu.action
-cpu.resetInterval
-cpu.smpAffinitized
-cpu.smpProcessorAffinityMask
-cpu.smpProcessorAffinityMask2
)

By appending "-?" to the command above, appcmd generates an error that lists all of the attributes that can be used with application pools.

Piping Output

You can pipe appcmd output to another appcmd command. Having this capability is extremely powerful, especially in the area of scripting functionality around appcmd.

The following command will find all application pools with names ending in "2007" and will then recycle each of them.

appcmd apppool list /name:"$=*2007" /xml | appcmd apppool recycle /in

(The "/in" switch causes the output from the first command to be sent to stdin.)

A more useful example might be to restart all application pools serving requests that have been executing for longer than a particular amount of time. The following command will recycle all application pools serving requests that have been executing for more than 30 seconds.

Appcmd list request /xml /time:"$>30000" | appcmd recycle apppool /in

In such situations, you might want to also obtain a list of the application pools. You can use multiple pipes to achieve that result.

Appcmd list request /xml /time:"$>30000" | appcmd list apppool /in /xml | appcmd recycle apppool /in

 

AppcmdUI

These examples only touch on the capabilities of appcmd.exe. One of the best ways to discover the capabilities of this tool is to use AppcmdUI. AppcmdUI is an interface into appcmd.exe. It gives you auto-completion for appcmd.exe commands and nicely formatted documentation so that you can more easily learn this powerful tool.

AppcmdUI is available from the IIS.net website.

By the way, those of you familiar with PowerShell might think that appcmd.exe uses PowerShell for some of its functionality. It doesn't. Therefore, appcmd.exe can be used with Windows 2008 Server Core as well.

Jim

Comments

  • Anonymous
    January 16, 2008
    PingBack from http://msdnrss.thecoderblogs.com/2008/01/16/cool-things-you-can-do-with-appcmd-in-iis-7/

  • Anonymous
    August 23, 2009
    I found some bugs here. In my machine (W2K8 / IIS7) the following command recycles all application pools: C:>%windir%system32inetsrvappcmd.exe list apppool /xml | %windir%system32inetsrvappcmd.exe recycle apppool /in

  • Anonymous
    August 23, 2009
    Hi, Gunnar. Yes, that's right. The command you posted should recycle all app pools. Jim