Updating all Work Item Type Definitions on a server using PowerShell

The esteemed Grant Holliday - recently posted: How do you update all Work Item Type Definitions on a server? using the Windows Shell.  The advantage of using Windows shell is that it's guaranteed to be on any server or workstation - the disadvantage the script must know in advance all Team Projects on the server (perhaps this is desired if you only want to update a subset of the TP's).  But if you want to reuses the script - you'll need to make sure you keep it updated with any TP's that are added to your TFS installation.

I'm  a big PowerShell fan - so when I was faced with the same need at a client - my first reaction was to write the script in PowerShell.  The advantage - it uses the TFS API to iterate the list of Team Projects.  Obviously this requires PowerShell to be installed - but I think most TFS mavens consider that a required install on their servers and workstations.  This becomes a moot point with Windows 7 and Windows Server 2008 R2 - as PowerShell is part of the install...

Anyway - here is my version of the same script - but in Powershell...  It takes advantage of James Manning's excellent "get-tfs.ps1" script to connect to TFS and load the API into Powershell

Note that I use the start-transcript (and stop-transcript) commands to save the output to a file to check for errors, etc to a file.

Here's my script

start-transcript

$server="http:\\TFSServer:8080"

#get tfs variable

$tfs = .\get-tfs.ps1 $server

$toolPath='C:\"Program Files"\"Microsoft Visual Studio 9.0"\Common7\IDE'

$xmlPath= 'c:\dev\CMMI-Custom\"MSF for CMMI Process Improvement - v4.2.1"\"WorkItem Tracking"\TypeDefinitions'

#get list of team projects

$projects = $tfs.css.ListAllprojects()

foreach ($project in $projects) {

     $projectName = "`"" + $project.Name + "`""

     "Processing Project: $projectName"

     "Importing Bug to TFS"

     $exec = "$toolPath\Witimport /f $xmlPath\bug.xml /p $projectName /t $server "

     $out = Invoke-Expression $exec

     $out

}

stop-transcript

 

 

Published 07 July 09 10:22 by DanielS
Filed under: ,

Comments

No Comments
Anonymous comments are disabled