Use AppCmd to Create Update Script for IIS Websites

      Comments Off on Use AppCmd to Create Update Script for IIS Websites

Here at Telligent when we update an existing website our normal procedure is to make an XCopy of the current web folder, apply the updates and then point IIS to the new folder.  This gives us a couple of advantages.  The first advantage being that we always have a backup that we can fail back to if there is any problem with the update we just performed. The second advantage is we don’t have to worry about files being locked and unable to overwrite.  The final advantage is that by pointing IIS to the new folder it automatically forces an application pool reset. 

Lately I’ve had the chance to play with IIS 7.0 and the new AppCmd.exe tool.  With it I’ve been able to create a script that prompts for source and destination directories as well as extracting files from a WinRAR archive and then points IIS to the new web folder.  I thought I’d share the script here:

echo off

Set /P src=[old folder date]
Set /P dest=[new folder date]
Set /P RARFile=[Name of Rar file]

xcopy d:\test\site1\%src% d:\test\site1\%dest% /o /e /y /c /i

“c:\program files\winrar\rar.exe” e -o+ -y d:\test\%rarfile% d:\test\site1\%dest%\

“c:\windows\system32\inetsrv\appcmd.exe” set vdir site1/ –physicalpath:d:\test\site1\%dest%

Echo “Site Update Complete”

I’m really looking forward to using IIS 7.0 in our production environments because with the new AppCmd.exe tool it is possible completely control everything IIS does with just one tool.  I’ve had to make a correction.  The physical path to the vdir wasn’t being set properly.  It needs the full path that I have added and highlighted.

Robba