Del via


ABC's of Appcmd (command line administration in IIS7)

So what is Appcmd.exe?

This is "one" command line tool to administer IIS7.  In IIS6 several of admin task were done using several scattered VBS script files. This made it difficult to find out what script needs to be run for eg. to get list of worker processes.

So IIS7 is powered with Appcmd.exe which provides all the options you need to administer IIS7.

Following are the options/categories available from a high level

SITE Administration of virtual sites
APP Administration of applications
VDIR Administration of virtual directories
APPPOOL Administration of application pools
CONFIG Administration of general configuration sections
WP Administration of worker processes
REQUEST Administration of HTTP requests
MODULE Administration of server modules
BACKUP Administration of server configuration backups
TRACE Working with failed request trace logs

Lets see how we can use it with an example

When I installed LH Server Beta (I rebuild my box quite frequently) I wanted to see how it's like to have 1000 websites running on IIS7.

So I created 1000 websites on my box.

Good scenario to use Appcmd.exe and also my MS-DOS experience. No I'm not gone nutts to create it using the UI :)

Steps required

  1. Wanted separate folders for each website
  2. Wanted to use same IP address and port for all websites
  3. Type a command and leave the box to create all the websites

Keep in mind I'm not talking about Server but my desktop machine. Yea its got 2GB RAM though.

Steps below

  1. Created a folder - E:\Websites
  2. I wrote a batch file (createsite.cmd) with the following
    MD E:\Websites\Site%1
    appcmd add site /name:"Site%1" /id:%1 /bindings:http/:*:80:site%1 /physicalPath:"E:\Websites\Site%1"
    appcmd start site "Site%1"
  3. Now the command to trigger the batch file where my MS-DOS experience came handy
    C:\FOR /L %i IN (2,1,5) DO createsite.cmd %i

FOR command is a batch file loop which simply works like 'for' loop in your favorite language

FOR /L %i IN (2,1,1000) DO createsite.cmd %i

is equivalent to the following in C

for ( i=2; i <= 1000; i++ )
createsite( i );

I started value of 'i' from 2 because "Default Website" has Site ID 1.

Hit enter and wait till the folders and websites are created for each iteration.

Bingo !!! 1000 websites ready to be administered or tested.

So the result would be
E:\Websites folder would have folders called Site2, Site3 etc... and in IIS there would be sites with name Site2, Site3 etc...

Lets revisit the appcmd command above once again

appcmd add site
/name:"Site%1" // website name
/id:%1 // Site ID
/bindings:http/:*:80:site%1 // site would have "All Unassigned" including host header with the site name
/physicalPath:"E:\Websites\Site%1" // Pointing to the physical folder for that site

appcmd start site "Site%1"  // pretty straight forward, it starts the website

What else can I do to extend this scenario?

  • Create Application Pools separately for each website
  • Create a simple ASP page and drop it in every folder created
  • Use TinyGET utility (available with IIS6 Resource Kit) to simulate request

Some other useful command options

Create Backup
C:\>appcmd add backup "backup before screwup"
BACKUP object "backup before screwup" added

List Backup
C:\>appcmd list backup
BACKUP "backup before screwup"

Restore from Backup
C:\>appcmd restore backup "backup before screwup"
Restored configuration from backup "backup before screwup"

Currently Executing Requests
C:\>appcmd list  request
REQUEST "fa00000080000487" (url:GET /highcpu.asp, time:1903 msec, client:localhost)

Will add more of this later...

Comments

  • Anonymous
    August 16, 2006
    Thank you for this introduction..
    Is there a manual where the top level command are listed.

    So there is
    appcmd.exe list bla bla
    appcmd,exe set bla bla

    What else is there possible?

    Thanks

    Thomas

  • Anonymous
    August 21, 2006
    appcmd /?

    The above would give you top level command list (which I have mentioned above in the table) and then you can drill down from there.

    For example next step could be
    appcmd site /?

    which would provide actions available for "site"

  • Anonymous
    December 03, 2006
    Where can i find appcmd.exe . Can someone mail me this file at shoeb@octaware.com Regards Shoeb

  • Anonymous
    March 03, 2007
    In reply to the last comment, in case anybody else runs into this page in the future with the same question, appcmd.exe is located in the %windir%system32inetsrv directory if you have IIS 7 installed on your machine. (where %windir% is your Windows installation directory)

  • Anonymous
    March 05, 2007
    Thanks Chris, for the quick reply to Shoeb's question!!!

  • Anonymous
    March 20, 2007
    Sukesh, thanks for the post!   Your example of using the tool from a batch file is a great example of how AppCmd can be used to quickly perform configuration and deployment tasks for IIS7. In the near future, I'll be posting an even cooler way to create a 1000 websites (or apps / apppools etc) on my blog, which should be orders of magnitude faster then just calling the tool. Check out the "Most Important AppCmd Commands" series on my blog: http://mvolo.com/blogs/serverside/archive/2007/03/18/Most-Important-AppCmd-Commands.aspx for this and other info about AppCmd, and keep those posts coming!

  • Anonymous
    December 10, 2007
    Do you know how to bind certificate to https via appcmd.exe?

  • Anonymous
    December 10, 2007
    Since SSL encryption/decryption happens in kernel mode (HTTP.SYS) configuration is done using ssh. > netsh http list sslcert Configuring an installed certificate (binding) for a website is explained in the following article. http://www.iis.net/articles/onepagearticle.ashx/IIS7/Managing-IIS7/Configuring-Security/Using-SSL/How-to-Setup-SSL-on-IIS7