How to Script / Automate IIS7 Configuration (without writing code)

I hear this question a lot in the http://forums.iis.net/, and thanks to Carlos and team's rocking Configuration Editor, figuring this out on your own is a breeze.  Here is how you can generate code for ANY IIS7 configuration change, without writing a line yourself.

1) download the IIS7 Administration Pack.  What, you don't have it already?  You're really missing out on some fantastic tools, including the Configuration Editor.  Learn more about the admin pack here http://learn.iis.net/page.aspx/401/using-the-administration-pack/  You can download x86 and x64 from http://www.iis.net/downloads.

2) open "IIS Manager" and click on the "Configuration Editor" feature under the "Management" category:

image

3) Find the configuration section(s) you want to edit using the drop-down combo box, in this case isapiFilters:

image

4) use the configuration editor to make your change.  In this case, I'm editing a collection, which pops up a collection editor where I can add items to the isapiFilter list by clicking 'add' in the task pane.

image

5) once you're done making any configuration updates, click on the 'Generate Script' task in the main Config Editor window:

image

6) the script generator creates three ways of automating the configuration change you just made  C#, JavaScript (again the AHAdmin COM interface) and AppCmd.exe

image

7) Copy and Paste these changes into your own script / code and whoila, you've got sample code for making any IIS7 configuration change.

You may also want to read up on the IIS7 Administration APIs.  You can find a lot more information here:

Using Scripts to Automate Management

Managing IIS with the IIS 7.0 PowerShell Provider

1 Comment

  • using System;
    using System.Text;
    using Microsoft.Web.Administration;

    internal static class Sample {

    private static void Main() {

    using(ServerManager serverManager = new ServerManager()) {
    Configuration config = serverManager.GetWebConfiguration(null);

    ConfigurationSection appSettingsSection = config.GetSection("appSettings");

    ConfigurationElementCollection appSettingsCollection = appSettingsSection.GetCollection();

    serverManager.CommitChanges();
    }
    }
    }

Comments have been disabled for this content.