When using multiple IIS server in a Load Balanced Environment it will  be alot of work to create all your website twice with the same settings on each webserver. Therefor it is possible to export and import your configuration from one webserver to the other. This will also be usefull when your upgrading from IIS 7 (Windows Server 2008) to IIS 7.5 (Windows Server 2008 R2).

When you create a website in IIS 7 or 7.5 a unique application pool will also be created and used by this website, that’s why you need to import these application pools first on the second webserver before importing the website(s).

To Export the Application Pools on IIS 7 :
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml

This will export all the application pools on your webserver, therefor you need to edit the apppools.xml and remove the application that you do not need to import for example:

  • DefaultAppPool
  • Classic .NET AppPool
  • SecurityTokenServiceApplicationPool

And other apppools that already exist on the second webserver, appcmd doesn’t skip already existing apppools, it just quit’s and doesn’t import any.

To import the Application Pools:
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml

All the AppPools in the xml will be created on your second webserver.

To Export all your website:
%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml

This will export all the websites on your webserver, therefor you need to edit the sites.xml and remove the websites that you do not need to import for example:

  • Default Website

And all other websites that already exist on the second webserver.

To Import the website:
%windir%\system32\inetsrv\appcmd add site /in < c:\sites.xml

It’s also possible to export a single website or application pool all you need to do is add the name of the Application Pool or Website to the command line:

To export/import a single application pool:
%windir%\system32\inetsrv\appcmd list apppool “MyAppPool” /config /xml > c:\myapppool.xml

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

To export/import a single website:
%windir%\system32\inetsrv\appcmd list site “MyWebsite” /config /xml > c:\mywebsite.xml

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

Tagged with:
 

37 Responses to Exporting and Importing Sites and App Pools from IIS 7 and 7.5

  1. Dan says:

    This is great. I would have loved a way to do all this from the GUI. Would have loved to just export out the XML, and Imported it on another server to create the specific site and the specific app pool.

  2. Eric says:

    I have tried a number of times to export a single website configuration and import it on another machine. The XML output from the command above looks correct. However, when I try to import the XM I always get:

    ERROR ( hresult:8007000d, message:Command execution failed.The data is invalid. )

    Any help would be appreciated.

    • Michael says:

      Hi Eric,

      Sorry for the late response, I was on my holiday. I couldn’t replicate the error, but i saw my XML was empty when i used the export for a single website command. If you use %windir%\system32\inetsrv\appcmd list site /config /xml > c:\mywebsite.xml the xml will contain all websites and you can edit the xml and trow away all the sites you don’t need.

      Hope this will help you.

      Michael

  3. Alexander says:

    Thank you very much for this, it saved me a lot of time. A few notes:

    1) I had to run the commandline as Administrator, else I received an error about permissions.
    2) Authentication settings (anonymous with specific account+password in my case) on the website were not transferred for some reason, so I had to set them again.

  4. Brian Cooperider says:

    When importing the websites I get the message “failed to add Duplicate collection element “default Web Site” I removed the following lines:

    What lines do I need to remove to not duplicate the default website?

    • Michael says:

      Hi Brian,

      Remove the first part in the exported XML

      up to

    • Alexander says:

      Additionally, if you’re exporting/importing from and to another webserver that’s not completely identical, you might get clashing ID’s on the sites, and hence the “duplicate” error. Hack the XML accordingly so they don’t clash.

  5. […] original: http://www.microsoftpro.nl/2011/01/27/exporting-and-importing-sites-and-app-pools-from-iis-7-and-7-5… Second Headautomation, Backup, IIS, Windows Server 2008 ← SBS 2008 Domain Password Password policy /* */ […]

  6. Brian Cooperider says:

    Thanks Mike,

    I actually got it working the other day by deleting the default website. Went to do a second machine the same way today and it’s only importing the default and not the rest. I can’t figure out why.

  7. Robert says:

    Here is the proper syntax to export an individual site:

    appcmd list SITE /site.name:SITENAME /config /xml > c:\SITENAME.xml

    • liz says:

      Robert,
      i tried your syntaxt for exporting an individual site. It does work. It just produces this:

  8. MKZA says:

    Great BUT I still cannot fathom why after so many years there is not a simple right click export from IIS manager ?? Microsoft continually misses the boat in providing simple time saving functionality, stuff we actually need.

  9. Sharad K Rathi says:

    Can you tell me how can transfer IIS FTP Accounts & Windows User Accounts from one server to other server?

    With Regards
    Sharad K Rathi

  10. kutegirl says:

    What about if Im exporting to another IIS server that already has other sites and configuration files defined. Will the import erase the existing configurations on the second server or will it merge the old with the new one?

    • Michael says:

      Hi,

      When you export the sites there will be an XML with al the configuration in it. When you have a site on the server where you want to import which has the same name, it will be overwritten. You can edit the XML and change the naming, or take out the config for one or more sites before importing.

      Regards,

      Michael

  11. Hugh Caldwell says:

    Just wanted to mention that these command have to be run in DOS window and not from Powershell. I’ve gotten used to using PS so I ran the export command from a PS window but since PS doesn’t recognize ‘<' I tried to run the import commands from a DOS prompt and got malformed XML erros. Running the export from a DOS prompt resolved this error.

  12. krishnakumar K says:

    Thanks a lot.. it saved a lot of time

  13. Diego says:

    Hi,
    great post!
    I have the same problem that Hugh Caldwell said.
    That would be a good to export and import configurations with PSExec but the problem is that PS doesn’t recognize ‘’.
    For example: C:\PS\psexec.exe -accepteula \\server -u user -p password %windir%\system32\inetsrv\appcmd.exe ADD SITE /IN < \\server\share\MySite.xml

    this NOT work
    Can you help me?
    Thanks
    Diego

    • Michael says:

      Hi Diego,

      I guess this is a short coming of PSExec it just hangs when you execute the command.

      I can’t help you with this one.

      Sorry

      Best regards,

      Michael

  14. James Bollam says:

    Hi, deleted the default site from IIS (yes I know daft), I don’t want to rebuild my server (server1).

    if I build another server (server2) on another server Could I use this method to move the default site from server2 to server1

    • Michael says:

      Hi Eddie,

      You can use this to re-create the default website, on the other hand you could just create an new website and point it to c:\inetpub\wwwroot this will have the same result.

  15. itismeap says:

    The scary thing about this export command is that the passwords for any service accounts are exposed in plain text!!! That is very suprising….

    • Michael says:

      That’s not nice, I’m affraid I cannot change that.

      As long as everyone knows it now and removes the export file after usage it will be OK I guess.

      Thanks for sharing your observation.

  16. Gireesh says:

    I have 10 websites and 10 application pools in IIS. As per the above commads, We can Export and Import All Config at a time. But i want to export only 5 websites and 5 application pools by using a single command. is this possible?. If it is possible Please let me know how to export.

    Thanks in Advance.

    Regards,
    Gireesh.

    • Michael says:

      Hi Gireesh,

      It is possible to export/import multiple individual site in a “single” command by seperating the command with a pipe |

      for example :

      appcmd list site site1 /config /xml > c:\site1.xml | appcmd list site site2 /config /xml > c:\site2.xml

      This will export 2 sites named site1 and site2 into 2 xml files, you can do the same for apppool’s.

      Regards,

      Michael

  17. Daniel says:

    _
    ( (( Thanks
    \ =\ For
    __\_ `-\ Posting
    (____))( \—- This!
    (____)) _
    (____))
    (____))____/—-

    -Juice

  18. Shashi says:

    Below commands are giving no output while exporting

    %windir%\system32\inetsrv\appcmd list site “MyWebsite” /config /xml > c:\mywebsite.xml

    appcmd list SITE /site.name:SITENAME /config /xml > c:\SITENAME.xml

    please help me!!!

    • Michael says:

      Hi,

      You need to change the “MyWebsite” to the name of your website.

      eg.

      %windir%\system32\inetsrv\appcmd list site “Default Web Site” /config /xml > c:\mywebsite.xml

      Regards,

      Michael

  19. Babu Ashok says:

    Very useful post.. Saved lots of time and effort in replicating site settings.

  20. Snark says:

    Merci, thanks, very helpfull for me.

    But export a single website didn’t work, even with right site name, I had to export full, purge in xml not needed site, then it’s ok.

    %windir%\system32\inetsrv\appcmd list site “DefaultPage” /config /xml > c:\mywebsite.xml

    Do not work for me on W2k8R2 (quite empty file).

    appcmd list SITE /site.name:SITENAME /config /xml > c:\SITENAME.xml
    => not tested, I have a workaround solution

  21. Luis Rocha says:

    Thanks for the great post! Just in case you want to use the import commands with powershell, you could use:

    gc .\apppools.xml | C:\Windows\System32\inetsrv\appcmd.exe add apppool /in

    and

    gc .\sites.xml | C:\Windows\System32\inetsrv\appcmd.exe add site /in

  22. Eric DUncan says:

    Thanks for this post.

    NOTE: It does not export the SSL binding settings. You still have to do this manually, though this saved a whole lotta time binding dozens of IPs and ports!

  23. Basavaraj says:

    Really nice and appriciated.. thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

captcha

Please enter the CAPTCHA text

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>