Exporting & Importing App Pools and Websites configuration between multiple IIS instances

One of the most boring things to do while configuring multiple web server nodes (cluster, server farm or other load balanced environments) is having to setup the entire website configuration tree in each IIS instance. Not to mention Application Pools, which are often a pain to configure properly.

Luckily enough, starting from IIS7+, there's a nice command-line utility called appcmd who can effectively export the entire IIS websites & app pools configuration in xml format and also import these same xml into another IIS instance. Let's see how we can do this.

Export the Application Pools

The first thing you have to do is to export/import the application pools, since they will most likely be used in your web sites and you won't be able to import those without having their relevant app pool into place. Here's the command-line:

%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml

 

This command will export all your application pools - including the default ones. You'll need to remove those, as they will most likely be in your target IIS instance with the same name and therefore they will raise a duplicate name error, blocking the whole import. In order to avoid that, open the newly created apppools.xml  file and remove the default ones such as:

  • DefaultAppPool
  • Classic .NET AppPool
  • .NET v2.0
  • .NET v2.0 Classic
  • .NET v4.5
  • .NET v4.5 Classic

... And also each one that's already present in your target. If you forget one, don't worry - you'll figure it out when you'll try to run the import procedure, which won't work.

Import the Application Pools

Copy the apppools.xml  file to your target webserver and run the following command:

%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml

 

Export the Websites

Right after the App Pools you can copy your website configuration. Open up again a command-line console on your source webserver and type in the following command:

%windir%\system32\inetsrv\appcmd list site /config /xml > c:\websites.xml

Again, you'll have to remove the default websites -  you'll most likely have only one default website, which is Default Website - as well as any other website you don't want to copy and/or is already existing on the target IIS instance, otherwise the import command won't work.

Import the Websites

Just like you did with the App Pools file, copy the websites.xml  file to your target webserver and run the following command:

%windir%\system32\inetsrv\appcmd add site /in < c:\websites.xml

 

Export/Import a single App Pool or Website

These commands can also be used to export/import a single application pool or a specific website. You just have to add their identifying name to the command-line, such as:

Export a specific Application Pool

%windir%\system32\inetsrv\appcmd list apppool "CustomAppPool" /config /xml > c:\customapppool.xml

Import a specific Application Pool

%windir%\system32\inetsrv\appcmd add apppool /in < c:\customapppool.xml

Export a specific Website

%windir%\system32\inetsrv\appcmd list site "CustomWebsite" /config /xml > c:\customwebsite.xml

Import a specific Website

%windir%\system32\inetsrv\appcmd add site /in < c:\customwebsite.xml

 

Happy coding!