The following are some of the command-line administrative tools you can use and their benefits:
PowerShell:
AppCmd:
Exposing key IIS Server management functionality
Easily controlling the server without using a GUI
Automating management tasks without writing code
In this article we focus on the Appcmd.exe utility, which is specifically designed to be used for IIS 7.0 management. Appcmd.exe can be found in the %systemroot%\system32\inetsrv directory. The following is a list of supported object types that you can configure using this tool:
SITE: Administration of virtual sites
APP: Administration of applications
VDIR: Administration of virtual directories
APPPOOL: Administration of application pools
WP: Administration of worker process
REQUEST: Administration of HTTP requests
BACKUP: Administration of server configuration backups
MODULE: Administration of server modules
TRACE: Working with failed request trace logs
Note
You can add the %systemroot%\system32\inetsrv directory to your path environment variables to be able to run Appcmd.exe from any location.
The
object that is being used defines the types of commands available for
the object. To see what commands are available and a brief description
of what the commands will do for a specific object, you can use appcmd <object> /?. For example, to see what commands are available for the APPPOOL object, follow these steps:
1. | Open a command prompt.
|
2. | Navigate to the inetsrv directory by typing CD\windows\system32\inetsrv.
|
3. | Type appcmd apppool /?. The available commands are now listed for the APPPOOL object:
- List: List the application pools.
- Set: Configure the application pool.
- Add: Add a new application pool.
- Delete: Delete the application pool.
- Start: Start the application pool.
- Stop: Stop the application pool.
- Recycle: Recycle the application pool.
|
You can customize your command further by using an optional parameter such as the following:
/?: Display help either from appcmd or appcmd <object>.
/text<:value>: Generate output in text format.
/xml: Generate output in XML format.
/in or-: Read and operate on XML input from standard input.
/config<:*>: Show configuration for displayed objects.
/metadata: Show configuration metadata when displaying configuration.
/commit: Set the path where configuration changes are saved.
/debug: Show debugging information for command execution.
Note
To see more details for these parameters, type appcmd.exe /?.
So now that you have a basic understanding of appcmd.exe, let’s take a look at how we can use it. First let see how we can get a list of the websites on our server:
1. | Type appcmd list site.
|
2. | A new line appears for each website, as shown in Figure 1, with the following details:
Name of the site ID Bindings State
|
Now let’s take a look at how to add, configure, and remove a site:
Add a Website Using appcmd.exe
To add a website, you need to provide some configuration parameters for the site. Here’s what you do:
1. | Type the following:
appcmd add site /name:NewSite /bindings:"http/*:802:" /physicalpath:"c:\NewSite"
The command returns three lines:
object "NewSite" added APP object "NewSite/" added VDIR object "NewSite/" added
|
2. | If desired, check in IIS Manager and confirm that the new website has been created.
|
Configure a Website Using appcmd.exe
Here’s how you reconfigure the port setting from 802 to 82 on the site you just created:
1. | Type the following:
appcmd set site "NewSite" /bindings:"http/*:82:"
When the command prompt is returned to you, the task is complete.
|
2. | If desired, you can check the bindings in IIS Manager to confirm the changes.
|
Delete a Website Using appcmd.exe
The website you have created will have a short life. You are now going to delete it:
1. | Type appcmd delete site "NewSite". The command returns SITE object "NewSite" deleted.
|
2. | Refresh the view in IIS Manager to confirm that the website NewSite has been deleted.
|
Now let’s take a look at backing up and restoring the web server configuration.
Back Up Your Configuration
To back up your configuration, type appcmd add backup “Backup config”. (If no name parameter is provided the backup will automatically generate a name, based on a timestamp.) The command returns BACKUP object “backup_config” added.
View Available Configuration Backups
To view available configuration backups, type appcmd list backup.
The command returns a list of all available backups of your
configuration, including any backups that VSS automatically created.
Restore Configuration Backups
To restore configuration backups, type appcmd restore backup “backup config”. This command returns Restored configuration from backup “backup config”.
Using appcmd.exe
can ease the burden of managing your IIS environment. Being able to run
many management tasks from a command line means that you will be able
to script these tasks and schedule them as needed.