What can AppCmd.exe do for an IIS Admin?
AppCmd.exe allows you to perform just about all the typical management functions you would want to perform using the CLI instead of the GUI. For example, here are some of the things that AppCmd.exe can do:
- Start and stop IIS web sites
- Create IIS websites, applications, application pools, and virtual directories
- Show running IIS processes and list currently executing requests
- Import, export, and search IIS ASP.NET configurations
The more you take the output of one AppCmd.exe command, combine it with scripting logic, and use that to perform another AppCmd.exe command, the greater the power for the application. In other words, while using AppCmd.exe to perform a onetime command or putting it in a Windows Desktop Shortcut to perform a frequent command may be very useful, you could get a ton more functionality by using AppCmd.exe in complex IIS administrative scripts.
Here are just a few practical applications for using AppCmd.exe:
- Start & Stop IIS sites from the command line
- Create a new IIS website or virtual directory (or make any IIS configuration change you want, really)
- Backup the IIS configuration
- Export IIS configurations
How do I use AppCmd.exe?
There are a couple things you need to know about using AppCmd, even before you execute your first AppCmd.exe command.
- You have to have IIS 7.x installed to get the AppCmd.exe command.
- You need to know where the AppCmd.exe command is located as it is not in the default PATH. In order to run AppCmd.exe, you will either need to change directory into %windir%\system32\inetsrv\ or add that directory to your PATH variable. On my Windows 2008 server with a default installation, AppCmd.exe was located in C:\Windows\System32\inetsrv.
Just like other Windows commands, you can get the basics of how to use the command by typing AppCmd.exe /?
You will find that the general command layout is:
APPCMD (command) (object-type) <identifier> < /parameter1:value1 ... >*
Note:
Do not let the slightly complex command layout scare you – AppCmd.exe is very easy to use. Let me show you how.
The basic commands used with AppCmd.exe are start, stop, list, add, delete, and set. Typically, each of these commands would be used with an object type that you are asking AppCmd.exe to perform the requested function on.
Possibilities of the object type are:
- Site – IIS virtual site
- App – IIS application
- Vdir – IIS virtual directory
- Apppool – IIS application pool
- Config – IIS general configuration
- Backup – IIS server configuration backups (and the restore command is also available)
- Wp – IIS worker processes
- Request – active HTTP requests
- Module – IIS server administration modules
- Trace – IIS server trace logs
As you can see, there is a lot you can do with AppCmd.exe but it does not have to be difficult it you use help along the way.
Making AppCmd.exe Easy by using Help
We said that AppCmd.exe /? will give you a large help page for AppCmd.exe. You can get more information about each of the different types of objects above by typing appcmd (object) /?
Here is an example:
Figure 1: Getting help for an AppCmd.exe Object Type
You can also get more help for each of the different commands AND each of the different object types. This means that there is a ton of help available. Meaning, with 10 different object types and at least 3+ commands for each (list, add, and delete usually), there are easily 30+ different help files available. Here is an example for using help where we learn what we can do with the add command and the vdir command together:
Figure 2: Getting help with AppCmd.exe's add and vdir options
If you use the help "/?" and list commands every step of the way, these commands will guide you through whatever task you are trying to perform with AppCmd.exe.
Five ways that you can use AppCmd.exe to make your IIS website administration easier
Sure, you can do just about everything in the IIS management MMC (GUI) that you can do with AppCmd.exe at the command line but GUI interfaces also have their disadvantages. To name a few - with a GUI you cannot do repetitive tasks quickly (like with a Windows Desktop Shortcut) nor can you use output from one AppCmd.exe output and send it to an AppCmd Action.
Here are 5 ways that using AppCmd.exe can make your IIS website administration easier:
1) Start and Stop IIS websites from the command line
This is actually very simple. If you don't know the name of your sites, just do:
Appcmd list sites
Figure 3: Listing out sites using AppCmd.exe
Now that you know what sites you have, you can start and stop your IIS web sites like this:
Appcmd start sites "Default Web Site"
(or whatever site you want to start)
Figure 4: Starting Websites with AppCmd.exe
By the way, stopping a website is just as easy.
2) Add a new website
Adding a new website is easy. Just use:
Appcmd add sites /name:"Dave's Site" /id:12 /bindings:http://mysite.com:80
Like this:
Figue 5: Adding a website with AppCmd
While this may add 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 for it. To get a more fully functioning IIS site, use the following two commands:
AppCmd add site /name:ddsite /id:99 /bindings:http/*:81: /physicalPath:C:\ddsite
AppCmd add app /site.name:DDSite /path:/ddapp /physicalPath:C:\sites\ddsite
3) Listing objects that meet certain information
Using the list command is easy. I showed you how to list our websites running on the server in #1, above. Notice in the output how you can see that the sites are running or not (the sites state). You can also list all objects (like sites) that meet certain criteria. For example, this command lists all sites that are stopped. Here is an example:
Figure 6: Showing all IIS websites that meet a certain state
4) Backing up you IIS configuration
AppCmd.exe can backup your IIS configuration using the add backup command. You can also list your commands with the list backup command the and the restore backup can put your backup data back where it needs to go with the restore backup command.
Below, you see me backing up my IIS configuration then listing out what backups were available after that.
Figure 7: Backing Up an IIS configuration
5) Report on IIS configurations
AppCmd has the power to report on your IIS configurations and export that configuration to a text file. To do this, just run:
Appcmd list site "sitename" /config
Here is what the output looks like:
Figure 8: Listing IIS website configuration
For some other great examples of using AppCmd.exe, see the following related sites:
- IIS.net - Getting Started with AppCmd.
- Microsoft - How to use the Appcmd.exe command-line tool to enable and configure HTTP logging and other features in Internet Information Services 7.0
- Micosoft - TechNet
No comments:
Post a Comment