AppCmd, in combination with WinRM, is the Windows Server IIS systems administrator’s swiss-army knife for his daily routine. This post introduces AppCmd and provides a lot of AppCmd examples.
AppCmd.exe is a command-line utility to manage IIS 7+ web servers. It exposes all important IIS server management functionality available through a set of intuitive management objects that can be manipulated through the cmd.exe or PowerShell command-line, or through PowerShell scripts. In this post you’ll find more information about AppCmd usage and examples.
AppCmd provides the ability to administer and maintain Windows Server IIS editions without a graphical user interface (or GUI), like Windows Server Core for example. Using AppCmd you can administer those IIS servers without the need for writing extensive scripts. On iis.net you’ll find the Getting started with AppCmd.exe, written by Mike Volodarsky, who also created the AppCmd tool. Some tasks you can use AppCmd for are:
In this AppCmd introduction post I’ll provide AppCmd examples to administer IIS.
AppCmd uses the following syntaxis for its commands:
AppCmd (command) (object-type) <identifier> </parameter1:value1 ...>
Some of AppCmd commands are
stop. Those commands are used for the following object-types:
vdir (virtual directory),
apppool (application pool),
wp (worker process),
binding. Of course not every object-type can be stopped or started, look up the available options using
AppCmd /? AppCmd site /? AppCmd config /? AppCmd list apppool /?
Now let’s dive into AppCmd with some examples! 🙂
Appcmd list site "Default Web Site"
This command provides some valuable information about the requested website, the Default Web Site in this case. Its output is:
SITE "Default Web Site" (id:1,bindings:http/*:80:,state:Started)
And this tells us the “Default Web Site” SITE-object has IIS website identifier 1, listens on all configured IP addresses configured for this web server (
*), on port 80 and the state of the website is “Started”.
By slightly altering the above
list site AppCmd command, you can list all websites matching a condition. You provide the condition as an AppCmd parameter, for example to list all sites that are in state Stopped:
AppCmd list sites /state:Stopped
Now you can start all those websites to make your customers happy. But you may not want to start a site that hasn’t got
serverAutoStart configured (it must be stopped for a reason then). Let’s add that as a condition:
AppCmd list sites /serverAutoStart:false /state:Stopped
Use the following AppCmd commands to stop a website or to start a website. Substitute “example.com” with the website name in question.
AppCmd stop site "example.com" AppCmd start site "example.com"
Starting and stopping a website with AppCmd is as easy as that.
Besides stopping and starting a website, you can use AppCmd to stop an application pool, start an application pool or recycle an application pool (recycling gracefully stops and restarts the applications pool). Once again, substitute “example.com”, but now with the application pool name in question.
AppCmd stop AppPool "example.com" AppCmd start AppPool "example.com" AppCmd start AppPool "example.com" /autoStart:true AppCmd recycle AppPool "example.com"
Because AppCmd supports the piping of additional commands, a
-xml) parameter to generate XML formatted output, and a
/in parameter to read and operate on XML input, it’s possible to pipe multiple AppCmd commands to start all stopped application pools in a single command / loop.
AppCmd list AppPools /state:stopped /xml | AppCmd start AppPool /in AppCmd list AppPools /state:stopped /xml | AppCmd start AppPool /in AppCmd list AppPools /state:stopped /autostart:true /xml | AppCmd start AppPool /in
The latter is my favorite. In a nutshell, what this does is:
/in, which is then fed to the
The last one has a condition
/autostart:true meaning, list only application pools that are supposed to be in Started state (because IIS starts an application pool with this setting automatically).
IIS 6.0 is now really ancient history, and an application pool set to Classic Pipeline Mode should be as well. Let’s force all Classic application pools to Integrated Pipeline Mode:
AppCmd list AppPools /xml | AppCmd set AppPool -managedpipelinemode:Integrated /in
In IIS 7, application pools run in one of two modes: integrated mode and classic mode. The application pool mode affects how the server processes requests for managed code. If a managed application runs in an application pool with integrated mode, the server will use the integrated request-processing pipelines of IIS and ASP.NET to process the request. However, if a managed application runs in an application pool with classic mode, the server will continue to route requests for managed code through Aspnet_isapi.dll, which processes requests the same as if the application were running in IIS 6.0.
Most managed applications should run successfully in application pools with integrated mode, but you may have to run applications in classic mode for compatibility reasons. Test the applications that are running in integrated mode first to determine whether you have to use classic mode.
AppCmd also exposes the fastCgi configuration of IIS, allowing you to change the current PHP fastCgi configuration. I’ve blogged on more than one occasion about IIS + PHP + fastCgi + AppCmd: here, here.
For all commands below, remember to escape single quotes
' in PowerShell with a back tick
`! Set or change an fastCgi PHP configuration setting:
AppCmd set config /section:system.webServer/fastCgi /[fullPath='c:\php7\php-cgi.exe'].instanceMaxRequests:10000 /commit:apphost
instanceMaxRequests was set to 5000, this command updates it to 10000 by overwriting the configuration with the new settings. To add an fastCgi property you can use almost the exact same command. For example if you want to add
signalBeforeTerminateSeconds as a property:
AppCmd set config /section:system.webServer/fastCgi /[fullPath='c:\php7\php-cgi.exe'].signalBeforeTerminateSeconds:5 /commit:apphost
Change fastCgi environment variables:
AppCmd set config /section:system.webServer/fastCgi /[fullPath='c:\php7\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS'].value:5001 /commit:apphost
To completely remove an fastCgi handler, for example for PHP 5.4, use:
AppCmd set config /section:system.webServer/fastCgi /-"[fullPath='c:\php54\php-cgi.exe']" /commit:apphost
An application pool often is configured to run as an unprivileged user. The Application Pool Identity is set to a custom account instead of a built-in account. You can lookup the application pool credentials using these two commands:
AppCmd list AppPool "example.com" /text:processModel.username AppCmd list AppPool "example.com" /text:processModel.password
To use AppCmd to create a website, you can use, and extend, the following example:
Appcmd add site /name:"example.com" /id:821398 /physicalPath:"c:\Inetpub\wwwroot\examplecom" /limits.maxconnections:1000 /serverAutostart:true
This creates a website called “example.com”, with IIS identifier 821398, it uses
c:\Inetpub\wwwroot\examplecom as its physical path. A limit of 1000 simultaneous connections is set, as is the Autostart property.
In earlier blog posts I provided some more examples to create application pool and websites with AppCmd: Add websites and application pools to IIS 7.5, 8.0 with PowerShell, in a for loop.
I mentioned WinRM, or Windows Remote Management, in the introduction of this article. You can use all these AppCmd commands with WinRM on remote web serves. Neat! 🙂 An example is to conditionally start Application Pools on remote IIS web servers. This is ideal for central IIS management situations.
My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 10 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization.
IIS application pool recycle on specific times, not regular time interval
Conditionally start Application Pools on remote IIS web servers
Custom PHP version on IIS Express and WebMatrix 3
Target multiple ASP.NET versions with AppCmd.exe
AppCmd 3 – websites en applicatiepools
Multiple IIS 6.0/7.5 Vulnerabilities