Tuesday, January 13, 2009

Switching Website Root With PowerShell

Gasp! Jim is actually writing a technical blog post!

I'm using Selenium to write UI/feature tests for Community Server and Evolution. I use these tests both as feature acceptance and as regression tests to make sure we didn't bust something while working on other parts of the system. In order for me to regression test, I need to easily switch my website between the release and latest trunk.

For example, I’ve got two virtual directories in IIS, one for release, one for functional tests against trunk:


   Default Web   (http://localhost)

           Community Server Release  (http://localhost/CS)

                  Filesystem: C:\Program Files\Telligent\Community Server 2008.5\Web

           CS from Subversion’s trunk (http://localhost/csfunctionaltests)

                  Filesystem: D:\TelligentSvn\CommunityServer\Core\Trunk\CommunityServer.Web

I can change this manually in IIS Manager via the virtual directory's property sheet, but that's slow and a lot of mouse clicks. I hate the mouse. Keyboard, FTW!

PowerShell, to the rescue! I'm only just (finally!) getting back to PowerShell after a couple years' hiatus, so the following script likely isn't as cool as it could be. Still, it does the job and I'll refactor later if needed.

param ([switch]$showCurrent, [switch]$trunk, [switch]$release)

if ($trunk -and $release)


"Only one of -trunk or -release can be used."




$cstests = $iis.psbase.children | where {$_.AppRoot -eq '/LM/W3SVC/1/Root/csfunctionaltests'}

if ($showCurrent)


     "`nCurrent path: " + $cstests.Path + "`n"



if ($trunk)


     # Path for trunk

     $path = "D:\TelligentSvn\CommunityServer\Core\Trunk\CommunityServer.Web"


if ($release)


     # Path for release

     $path = "C:\Program Files\Telligent\Community Server 2008.5\Web"




iisreset /noforce

$cstests = $iis.psbase.children | where {$_.AppRoot -eq '/LM/W3SVC/1/Root/csfunctionaltests'}

"`nNew path for csfunctionaltests: " + $cstests.Path + "`n"

Save this as ChangeRoot.ps1, edit the trunk and release paths for your environment and invoke it with "ChangeRoot.ps1 -trunk" or "ChangeRoot.ps1 -release" to change appropriately. Use the "-showCurrent" to tell you which path you're currently using.


aliya seen said...

Smart work! Really interesting to read the article! You deserve great appreciation and expect many more good quality articles from you! Keep writing! create your own timeline

Shapath Das said...

Writing piece of writing desires thorough and in-depth data of the topic undertaken for the study. It got to be in-line with the topic of your analysis. pa schools in maine

Eron Hossain said...

College life is stressful and often times can lead to a sharp decline in the amount of time spent doing one's school work. For those of you that procrastinate, please read on for an in depth discussion on how to write a paper the night before it's due. cheat sheet template word

Subscribe (RSS)

The Leadership Journey