Skip to content

Instantly share code, notes, and snippets.

@SzymonPobiega
Created May 11, 2012 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SzymonPobiega/2657868 to your computer and use it in GitHub Desktop.
Save SzymonPobiega/2657868 to your computer and use it in GitHub Desktop.
Branch switching script
#
# The script switches IIS web applications to point to some other directory. It is very usefull when frequently changing branches.
# The script assumes SVN-ish branch structure like this:
# Root
# |
# |--Branches
# | |
# | |--Branch 1
# | |
# | \--Branch 2
# |
# \--Trunk
# |
# |--First.Web.Project
# |
# \--Second.Web.Project
#
# The list of web projects to use is provided via 'webapps.txt' file with following structure:
# app;dir
# webapp1;First.Web.Project
# webapp2;Second.Web.Project
#
param (
[string]$Root = $(Throw "Source code root folder not specified"),
[string]$Branch = $(Throw "Branch not specified")
)
$websites = Import-Csv "webapps.txt" -Delimiter ";"
function Execute-Cmd([string]$source, [string]$command, [string]$message) {
Write-Host "${message}..." -NoNewline
Write-Debug "${source}: ${command}"
$output = cmd.exe /C $command
if ($?) {
Write-Host "OK"
} else {
Write-Host "Failed"
throw "Failed ${message}"
}
}
if ($Branch -eq "Trunk") {
$root_dir = "${Root}\Code\Trunk\"
} else {
$root_dir = "${Root}\Code\Branches\${Branch}\"
}
$websites | ForEach-Object {
$dir = $_.dir
$app = $_.app
$work_dir = $root_dir + $dir
$params = "set app `"Default Web Site/$app`" -[path='/'].physicalpath:`"${work_dir}`""
$command = "$env:SystemRoot\system32\inetsrv\appcmd $params"
$message = "Switching working directory of $app to $work_dir"
Execute-Cmd "APPCMD" $command $message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment