Exporting and Importing Sites and App Pools from IIS 7 and 7.5
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
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.
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.
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
I have same issue occur but i have exported all sites so when we import into other server it’s come.However , when we import all app pools first so it is easily done from the xml file which we exported.
So please guide me what will we do now for all sites.However , All sites in IIS in 2nd Server is empty now for the safe side.
I have same issue occur but i have exported all sites so when we import into other server it’s come.However , when we import all app pools first so it is easily done from the xml file which we exported.
So please guide me what will we do now for all sites.However , All sites in IIS in 2nd Server is empty now for the safe side.
I Have identically issue but in my source server I had Advanced Logs installed and in the New server don´t have, I edited my XML and remove the instructions and solve this mistake. If you have any feature enable in source or install in the new or remove the instructions on XML.
removing the AdvancedLogging node resolved the issue for me as well, thank you so much!
Very late response but if anyone else has this issue, for me it was because I had an unclosed string in the config file which had obviously stuck after removing the default app pools from the config. Worth checking you don’t have anything similar.
This issue is because you have one extra configuration in the source server that the destination server doesn’t have. In my case I have the extra line:
Make an export file for each server and compare the lines.
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.
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?
Hi Brian,
Remove the first part in the exported XML
up to
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.
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.
Here is the proper syntax to export an individual site:
appcmd list SITE /site.name:SITENAME /config /xml > c:\SITENAME.xml
Robert,
i tried your syntaxt for exporting an individual site. It does work. It just produces this:
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.
Can you tell me how can transfer IIS FTP Accounts & Windows User Accounts from one server to other server?
With Regards
Sharad K Rathi
Hello Sharad,
The local windows users can be migrated with this document : http://technet.microsoft.com/nl-nl/library/dd379531(v=ws.10).aspx
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?
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
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.
Thanks a lot.. it saved a lot of time
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
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
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
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.
The scary thing about this export command is that the passwords for any service accounts are exposed in plain text!!! That is very suprising….
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.
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.
Hi Gireesh,
It is possible to export/import multiple individual site in a “single” command by seperating the command with a pipe |
for example :
This will export 2 sites named site1 and site2 into 2 xml files, you can do the same for apppool’s.
Regards,
Michael
_
( (( Thanks
\ =\ For
__\_ `-\ Posting
(____))( \—- This!
(____)) _
(____))
(____))____/—-
-Juice
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!!!
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
Very useful post.. Saved lots of time and effort in replicating site settings.
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
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
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!
Really nice and appriciated.. thanks
Very good article Michael
really helpful information saved my lots of time while re-configuring to new server
As others have said, this is an outstanding article and a real timesaver.
One thing I’d like to add to it, though…if you have any kind of duplicate issue, the sites/app pools that you add prior to the duplicate issue won’t get added. Therefore, you’ll need to rerun the commands once you remove the duplicate site/app pool. Don’t edit anything else; just the duplicate site/app pool.
Anyway, much appreciated!
What about exporting a virtual directory instead of the whole website. Unfortunately my company really uses virtual directories when they should be creating separate websites.
I don’t want to clobber or propagate changes to any other virtual directories that are not mine on the other server.
Is this going to work with our asp.net apps which we need to move from IIS 7.5 (Windows Server 2008 R2) to IIS 8.5 (Windows Server 2012 R2) ?
we want to import or export sites and apppools from one computer to another computer at a time is it possible?
sorry for the typo. another means multiple computers is it possible?
Hello Krishna,
The export generates xml files, the can be imported on as many computers you wish.
Hi
We are planning to migrate the IIS 7 & IIS 7.5 to IIS 8 .
so we can use the same export and import command for the same.
Note : Migrating from Windows 2008 to Windows 2012 OS
Let me know ,If you have any other command for export & import command for the same.
Thanks
Rajesh Kannan R
Hi, this methode can be used for this upgrade scenario
Hi,
I am trting to Import the XML file into new destination servre , but getting below error. Kindly check and help ASAP.
C:\Windows\System32\inetsrv>appcmd.exe add site /in < C:\Test.xml
ERROR ( hresult:8007000d, message:Command execution failed.
The data is invalid.
)
New Destination server is Windows 2012 OS + IIS 8.5
Source server is Windows 2008 OS + IIS 7.5
Thanks
Rajesh Kannan R
Hello Michael,
I need to migrate the My IIS 6.0 Version sites in to IIS 8.5 Version. Kindly help me how to migrate and share the steps also.
Note : we don’t have appcmd in IIS 6.0 version, so i cannot export the apppool and site in same.
Thanks
Rajesh Kannan
Hi Rajesh, Please try this method : http://www.iis.net/learn/publish/using-web-deploy/migrate-a-web-site-from-iis-60-to-iis-7-or-above
Sorry, this is working now for an individual site:
%windir%\system32\inetsrv\appcmd list SITE /site.name:SITENAME /config /metadata /xml > d:\SITENAME.xml
For single site export the examples in the article work but DO NOT use double quotes.
Great post. Saved me a lot of time.
Use this syntax to export a single file with all content (imagine a site named “wordpress” and replace that accordingly with your site name instead: “%windir%\system32\inetsrv\appcmd list SITE /site.name:wordpress /config:* /metadata /xml /debug > C:\folder\wordpress.xml”
Use this syntax to export a single site with all content (imagine a site named “wordpress” and replace that accordingly with your site name instead:
“%windir%\system32\inetsrv\appcmd list SITE /site.name:wordpress /config:* /metadata /xml /debug > C:\folder\wordpress.xml”
I have export all sites in xml from Server1 and the Server2 is already have some sites and its App pools so when we import Server1 xml exportrd file to Server2.
It is not allowing to do this.
Thanks Its worked for me…
It worked for Me… Thank you.
Really nice and Good article.
Thanks a lot.
Note: If your target has existing sites you may need to re-set all the IDs in your xml so they don’t clash with existing IDs
Resolved!!!
I resolved the issue. The problem was the authorization rules don’t export.
https://docs.microsoft.com/en-us/iis/configuration/system.ftpserver/security/authorization/
I used the following command to add allow USERS and Read/Write
appcmd.exe set config “MYWEBSITE” -section:system.ftpServer/security/authorization /+”[accessType=’Allow’,roles=’Users’,permissions=’Read, Write’]” /commit:apphost
All good now!!!
Hi I am getting following error:-
ERROR ( hresult:80070057, message:Failed to commit configuration changes.
The parameter is incorrect.
).
Please help me on this.
I had run this command “appcmd add apppool /in <c:\apppools.xml"
What would I need to change if the websites are not stored in the C”\windir\system32\inetsrv\ directory? For example, if they are placed in C:\web or C:\HostingSpaces? Sorry, I don’t normally do this stuff, but it’s been dumped in my lap do to the loss of my husband and I need to get a list of the websites currently in IIS so I can pass the list on to someone that will be taking things over for me.
Amazing, right in the point! Nicely done!
I want to elaborate a bit on something that some people in the comments were trying to help with.
Beware that when you do the import of a site or sites, you may get a “Failed to add duplicate collection element” error (even after deleting the default site as warned about above).
The problem is that the export of the sites from the source server will have stored in the websites.xml the “id” of the site in IIS–as it was on THAT source server. But if you have defined any sites on the server you are importing TO, you may have sites that ALREADY use that ID. And THAT is the reason for the conflict (though the error does not make that clear). I experienced this and helped someone solve it.
The solution is to go to IIS, choose “sites” (which will show all your sites on the right), and click the “id” column to sort that list by id. Now look at the largest number there. Let’s say it’s 7. We can tell the websites.xml file to have all the sites start with 10 (it’s not important that there “be no gaps” in the number. Such gaps can happen when you merely delete a site in the IIS UI.)
So now go into the websites.xml file, and you will see that for each site, there are TWO references to the site “ID” (in the first couple of XML lines per site). Change those two references to use that next number, like 10. Then find the next site’s XML elements, and change its two site ID values to 11, and so on.
Save the file, then try the import step again. That solved the problem for me.
I appreciate you. This just saved me a ton of time and was so simple. 13 years 9 months and 30 days after you wrote this… It’s still helping people.
BRAVO GOOD SIR!
Thank you, nice to hear it is still relevant.