Tuesday, December 8, 2009

Migrating from IIS 5/6 to IIS 7 manually

In IIS 7, a new utility is introduced  it is known as appcmd.

In order to run the commands below effectively, you need to open a command prompt session (running as Administrator).  I will not repeat what I have covered in the previous article on IIS 5 to IIS 6 but following the concept covered there, just change some minor approach and use the new command.

It is located in %windir%/system32/inetsrv/appcmd.exe

To get the format for the files needed to configure your virtual directory, the easiest way is to use the command as follows:

%windir%/system32/inetsrv/appcmd list vdir /xml

The output will look like this:

<?xml version="1.0" encoding="UTF-8"?>
    <VDIR physicalPath="%SystemDrive%\inetpub\wwwroot" path="/" APP.NAME="Default Web Site/" VDIR.NAME="Default Web Site/" />
    <VDIR physicalPath="C:\webfiles\t2" path="/test3" APP.NAME="Default Web Site/" VDIR.NAME="Default Web Site/test3" />
    <VDIR physicalPath="C:\webfiles\t3" path="/test4" APP.NAME="Default Web Site/" VDIR.NAME="Default Web Site/test4" />
    <VDIR physicalPath="C:\webfiles\t4" path="/test5" APP.NAME="Default Web Site/" VDIR.NAME="Default Web Site/test5" />
    <VDIR physicalPath="C:\webfiles\t1" path="/" APP.NAME="Default Web Site/test2" VDIR.NAME="Default Web Site/test2/" />

A few things to note.  If you want to make the virtual folder an application, then you need to change the APP.Name  to include the application name as in the case above where t2 is known as test2.  Also the path is the path relative to the application.

You can then copy this listing and use it as a template for your migration.  To get a list of application pool, use the following command:

%windir%\system32\inetsrv\appcmd list apppool /xml

The output will look like this:

<?xml version="1.0" encoding="UTF-8"?>
    <APPPOOL APPPOOL.NAME="DefaultAppPool" PipelineMode="Integrated" RuntimeVersion="v2.0" state="Started" />
    <APPPOOL APPPOOL.NAME="Classic .NET AppPool" PipelineMode="Classic" RuntimeVersion="v2.0" state="Started" />
    <APPPOOL APPPOOL.NAME="test" PipelineMode="Integrated" RuntimeVersion="v2.0" state="Started" />
    <APPPOOL APPPOOL.NAME="frame1.1" PipelineMode="Integrated" RuntimeVersion="" state="Started" />

If you want to add as an application folder, a quicker way is to use following command to get the default format:

%windir%\system32\inetsrv\appcmd list app /xml /config

Output will look something like this:

<?xml version="1.0" encoding="UTF-8"?>
    <APP path="/" APP.NAME="Default Web Site/" APPPOOL.NAME="DefaultAppPool" SITE.NAME="Default Web Site">
        <application path="/">
            <virtualDirectoryDefaults />
            <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
            <virtualDirectory path="/test3" physicalPath="C:\webfiles\t2" />
            <virtualDirectory path="/test4" physicalPath="C:\webfiles\t3" />
            <virtualDirectory path="/test5" physicalPath="C:\webfiles\t4" />
    <APP path="/test2" APP.NAME="Default Web Site/test2" APPPOOL.NAME="test" SITE.NAME="Default Web Site">
        <application path="/test2" applicationPool="test">
            <virtualDirectoryDefaults />
            <virtualDirectory path="/" physicalPath="C:\webfiles\t1" />

Once you have all the above format, you can then copy into a text editor and add in the required virtual folder or apps that you want to add.  It is probably easier to manually configure the application pools and then use the appcmd to add in the virtual applications.  Once you have your commands ready, use the following command:

For adding virtual directory, type the following command and then it will put you into the next line.  When it does that, paste your XML string to the console.  Once the xml is pasted, add one or two lines at the bottom and press Control Z to mark the end.

%windir%\system32\inetsrv\appcmd add vdir /in

Same with adding app and apppools.

%windir%\system32\inetsrv\appcmd add app /in


Xavstarblues said...

I am currently preparing a similar migration, does this include the copy of the rights?
I did not see anything mentionning it in your article.


Strovek said...


The method displayed here does not include copying rights. This is because each account has a unique ID which is different on different servers (the id is generated by the server when the account is created).

The applications I created uses its own authentication (LDAP) and the logic on who is allowed access is done at the application level and not at the server level. With that approach I do not have to worry about transferring the rights when migrating to a new server.