Exporting & Importing App Pools and Websites configuration between multiple IIS instances
Sometimes we have to configure multiple web servers or migrate entire website configuration to another server. It will be a lot of work to create your entire website twice with the same settings on each web server. Therefore it is possible to export and import your configuration from one web server to the other.
We can do this command-line utility called appcmd which can effectively export the entire IIS websites & app pools configuration in xml format and also import this exported xml into another IIS instance.
AppCmd.exe is the single command line tool for managing IIS 7 and above. It exposes all key server management functionality through a set of intuitive management objects that can be manipulated from the command line or from scripts.
Some of the things you can do with AppCmd:
- Create and configure sites, apps, application pools, and virtual directories
- Start and stop sites, and recycle application pools
- List running worker processes, and examine currently executing requests
- Search, manipulate, export, and import IIS and ASP.NET configuration
We can get help for AppCmd what are the available options using /?:
- AppCmd /?
- AppCmd site /?
- AppCmd config /?
- AppCmd list apppool /?
This blog discusses simplifying the Exporting & Importing process. This will work for IIS 7, IIS 7.5, IIS 8, IIS 8.5
Export the Application Pools
We can export and 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.
<strong>C:\Windows\System32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml</strong>
This command will export all your application pools – including the default application pool. You have 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:
- Classic .NET AppPool
- .NET v2.0
- .NET v2.0 Classic
- .NET v4.5
- .NET v4.5 Classic
Import the Application Pools
Copy the apppools.xml file to your target webserver and run the following command:
C:\Windows\System32\inetsrv\appcmd add apppool /in < c:\apppools.xml
All Application Pool mentioned in the xml file will be created on your target IIS instance.
Export the Websites
Export the all website with the following command:
C:\Windows\System32\inetsrv\appcmd list site /config /xml > c:\mysites.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:
C:\Windows\System32\inetsrv\appcmd add site /in < c:\mysites.xml