So you’ve been given a project to work on.  Namely convert this project from this technology to that technology and your in luck because you have TFS.

The pain in the backside bit is now I’ve you have got to enter all the tasks into TFS which in itself is going to take ages.

Enter the wonderful world of Powershell !  This is the kind of repetitive task that PowerShell is good at it can loop thru things and use the .NET object model, Easy!

So here is a code snippet that rips thru aspx pages and creates the TFS entries.

It will use the Current Logged in User for the access and the "assigned To"

so if you need to change that, well I’ll let you figure that out.

You will need to need to change the TFS Url the ProjectName and possibly the WorkItemType (if you dont want tasks)

 

cls
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
cd "D:DevMyProject"

[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer("http://tfs:8080/tfs/defaultcollection")
$WorkItemStore=$tfs.TfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

$project=$WorkItemStore.Projects["MyProject"]

$type=$project.WorkItemTypes["Task"]

#I made this bit over complicated so that you can insert your own regex in here

$files = Get-ChildItem . | where-object {$_.name -match "^.*.aspx$"}

foreach ($file in $files)
{

    $item = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem $type

    $item.Title = "Convert ASPX Page – " + $file.name
    $item.AreaPath = "MyProject"
    $item.IterationPath = "Iteration 4"
    $item.save()

}

 

Technorati Tags: ,,
Advertisements