Using Windows commands to copy existing IIS site details to another server. Exporting and subsequently importing the IIS settings.
Rebuilding a Windows server I wanted to keep the IIS configuration. The websites implemented within IIS on the existing website to be copied across to IIS on the new, replacement, web server.
I was interested in transferring the site details and their associated application pools.
I was to backup the existing sites and application pool configuration, and import once more after the sever was re-installed.
The following commands are run from the command line. PowerShell.
Exporting
To export the sites the generic command is:
%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
Which translates as:
c:\windows\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
Similarly to export the application pools the generic command is:
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
Which becomes:
c:\windows\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
Importing
Similar to the export but here are the items for importing the sites and application pools previously exported. First the recommended commands to implement.
Application pools, generic command
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
in practice:
c:\windows\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
Sites generic command:
%windir%\system32\inetsrv\appcmd add site /in < c:\sites.xml
Similarly this becomes:
c:\windows\system32\inetsrv\appcmd add site /in < c:\sites.xml
However these two commands gave the error
At line:1 char:6
The '<' operator is reserved for future use
The alternatives which I used for importing were:
get-content C:\apppool.xml | & C:\Windows\System32\inetsrv\appcmd.exe add apppool /in
and similarly:
get-content C:\sites.xml | & C:\Windows\System32\inetsrv\appcmd.exe add site /in
There was still an error. I found the exported file had a stray illegal character at the end. Removing this allowed the import to proceed.


