Configure IIS 7 from the command line using Appcmd.exe - Part 1

This series will introduce how to use the IIS 7.0 command line called AppCmd.exe to query objects on the web server and display the output as text or XML.
David Davis

In this series, I will show you how to use the new IIS 7.0 command line called AppCmd.exe to query objects on the web server and display the output as text. or XML.

Introduce

IS 7.0 provides a new command line tool, AppCmd.exe, that allows you to configure and query objects on your web server, then display the output as text or XML. In the first part of this series, we will show you what this tool is, how to use it, and how to perform common IIS administrative tasks such as creating new sites, stopping them. or start services and view the status of the site.

What can AppCmd.exe do with IIS administration?

AppCmd.exe allows you to perform all typical management functions using the CLI instead of the GUI. For example, here are some things that AppCmd.exe can do:

  1. Start and stop IIS web site
  2. Create applications, virtual directories and IIS websites
  3. Displays the running of IIS processes and lists the currently executing requirements
  4. Import, export and search ASP.NET IIS configurations

The better you use the output of an AppCmd.exe command, combine it with the logic script and use it to execute another AppCmd.exe command, the more power you will create for the application. In other words, while using AppCmd.exe to perform a certain command or placing that command on a Shortcut on the Desktop to make a good command to use is very useful, you can create a lot of functions. another by using AppCmd.exe in more complex IIS admin scripts.

These are just some typical applications for using AppCmd.exe:

  1. Start & Stop IIS sites from the command line
  2. Create a new IIS website or virtual directory (or make a change to IIS configuration)
  3. Backup IIS configuration
  4. Export IIS configuration

How to use AppCmd.exe

There are a few things you need to know about using AppCmd, even before you execute the AppCmd.exe command first.

  1. You must have IIS 7.x installed to support AppCmd.exe commands
  2. Know where the AppCmd.exe command is located because it is not in the default path. To run AppCmd.exe, you can use the way to change the directory to % windir% system32inetsrv or add that directory to your path variable. On our Windows 2008 server with the default installation. AppCmd.exe is located in C: WindowsSystem32inetsrv.

Like other Windows commands, you can use the basics of using commands by typing AppCmd.exe /?

You will see the layout of the command in general as follows:

APPCMD (command) (object-type) *

Note: Not too worried about the complexity of this command - AppCmd.exe is easy to use. We will show you how to use it.

The basic commands used with AppCmd.exe are start, stop, list, add, delete, and set . Typically each of these commands will be used with an object type that you will require AppCmd.exe to perform its desired function.

The types of objects here are:

  1. Site - IIS virtual site
  2. App - IIS application
  3. Vdir - IIS virtual directory
  4. Apppool - IIS application pool
  5. Config - IIS general configuration
  6. Backup - IIS server configuration backups (you can also use the restore command)
  7. Wp - IIS worker processes
  8. Request - active HTTP requests
  9. Modules - IIS server administration modules
  10. Trace - IIS server trace logs

As you can see, there are many things you can do with AppCmd.exe, but it is not that difficult if you use help.

Use AppCmd.exe easily with help

We said that AppCmd.exe /? It will allow you to get help on AppCmd.exe. You can get information about object types by typing appcmd (object) /?

Here is an example:

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 1Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 1
Figure 1: Get help information for an AppCmd.exe object type

You can also get more help information for different commands on each and every type of object. This means that there is a lot of help here for you. With 10 different object types and at least 3+ commands for each type (list, add and delete are regular commands), there are more than 30 different help files available. Here's an example of how to use help, which helps us know what can be done with the add command and the vdir command together:

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 2Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 2

Figure 2: Get help information with AppCmd.exe add and vdir options

If using help '/?' and listing step-by-step commands will give you instructions on how to perform any tasks you want to perform with AppCmd.exe.

5 ways you can use AppCmd.exe to make IIS website administration tasks easy

Ensure that everything can be done in the IIS management MMC (GUI) can be done with AppCmd.exe at the command prompt, but the GUI interfaces also have its drawbacks. To put a few names - with the GUI you cannot perform repetitive tasks (like a Windows Desktop Shortcut) nor can you use the output from an AppCmd.exe output and send it to an AppCmd ​​Action.

Here are 5 ways to use AppCmd.exe to make your IIS website administration task easier:

1. Start and Stop IIS websites from the command line

This is indeed a simple task if you don't know your site's name, just do it:

Appcmd list sites

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 3Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 3

Figure 3: List sites using AppCmd.exe

Now you will know what sites you have and can start or stop IIS web sites as follows:

Appcmd start sites 'Default Web Site'
(or any site you want to start)

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 4Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 4

Figure 4: Start Website with AppCmd.exe

That way, it's easy to stop a website.

2. Add a new website

Adding a new website is also easy. Just use:

Appcmd add sites / name: 'Dave's Site' / id: 12 /bindings:http://mysite.com:80

As follows:

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 5Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 5

Figure 5: Adding a website with AppCmd

This way only adds a new website, that website may not be as complete as a site added in the GUI unless all command options are added then an application is added to it. To get the full functionality of the IIS site, use the following command:

AppCmd ​​add site / name: ddsite / id: 99 / bindings: http / *: 81: / physicalPath: C: ddsite
AppCmd ​​add app /site.name:DDSite / path: / ddapp / physicalPath: C: sitesddsite

3. List the objects with certain information

Using the listed command is easy. We showed you how to list your website running on the server in way 1 above. Note in the output that you can see that the site may be running or not running (the status of the sites). You can list all objects (like site) with certain information. For example, this command will list all sites that are stopped. Here is an example of how to do it:

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 6Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 6

Figure 6: Shows all IIS websites that have a certain status

4. Backup IIS configuration

AppCmd.exe can backup IIS configuration using the add backup command . You can also list your commands using the list backup and restore backup commands that can bring the backup data back to where it is needed with the command.

Below you can see that we have backed up our IIS configuration and then list what backups are available after that.

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 7Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 7

Figure 7: Backup the IIS configuration

5. Report on IIS configuration

AppCmd ​​has the power to report IIS configurations and export the configuration to a text file. To do that, simply run:

Appcmd list site 'sitename' / config

This is what the output of the implementation process:

Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 8Configure IIS 7 from the command line using Appcmd.exe - Part 1 Picture 8

Figure 8: List IIS website configuration

Conclude

AppCmd.exe is indeed a command line tool for useful for IIS 7.x. AppCmd.exe can say that all IIS website configuration tasks can be done from the command line. It is a powerful support for Windows / IIS web administrators to know how to use it correctly to quickly perform common IIS tasks. In this article, you not only know what AppCmd.exe is but also know all that it can do for you in this way.

4.1 ★ | 28 Vote