A cacophony of ramblings from my potpourri of notes
|
Subscribe
| |  |
Search
Categories
On this page...
| September, 2008 (1) |
| August, 2008 (2) |
| July, 2008 (3) |
| June, 2008 (9) |
| May, 2008 (3) |
| December, 2007 (1) |
| August, 2007 (1) |
| July, 2007 (1) |
| June, 2007 (3) |
| April, 2007 (3) |
| February, 2007 (4) |
| January, 2007 (1) |
| December, 2006 (1) |
| November, 2006 (3) |
| October, 2006 (5) |
| September, 2006 (4) |
| August, 2006 (4) |
| July, 2006 (6) |
| May, 2006 (1) |
| March, 2006 (1) |
| February, 2006 (7) |
| January, 2006 (1) |
| November, 2005 (4) |
| October, 2005 (7) |
| September, 2005 (7) |
| August, 2005 (7) |
| July, 2005 (9) |
| June, 2005 (12) |
| May, 2005 (3) |
| April, 2005 (8) |
| March, 2005 (8) |
| February, 2005 (10) |
| January, 2005 (3) |
| December, 2004 (4) |
| November, 2004 (1) |
| September, 2004 (4) |
| August, 2004 (1) |
| July, 2004 (1) |
| June, 2004 (8) |
| May, 2004 (5) |
| April, 2004 (16) |
| March, 2004 (7) |
| February, 2004 (13) |
| January, 2004 (16) |
| December, 2003 (17) |
| November, 2003 (13) |
| October, 2003 (13) |
| September, 2003 (30) |
| August, 2003 (33) |
| July, 2003 (66) |
| June, 2003 (29) |
| May, 2003 (48) |
| April, 2003 (83) |
| March, 2003 (26) |
| February, 2003 (23) |
| January, 2003 (31) |
| December, 2002 (14) |
| November, 2002 (19) |
| October, 2002 (13) |
|

Tuesday, September 26, 2006
Creating a TFS Work Item from PowerShell
I came across a PowerShell script for creating TFS Work Items from Alan Stevens today. There are a couple more thougts and ideas I would add. Here is the output from my interactive PowerShell session (notice that I start with Alan's code to load the TFS assemblies. However, I begin to vary shortly after that.
|
>$key = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\VisualStudio\8.0 >$dir = [string] (Get-ItemProperty $key.InstallDir) >$dir += "PrivateAssemblies\" >$lib = $dir + "Microsoft.TeamFoundation.WorkItemTracking.Client.dll" >[Reflection.Assembly]::LoadFrom($lib) >$lib = $dir + "Microsoft.TeamFoundation.Client.dll" >[Reflection.Assembly]::LoadFrom($lib) >$server="tfs" >$NetCredentials=new-object System.Net.NetworkCredential ("Mark", "P@ssw0rd", "Michaelis") > $tfs =new-object Microsoft.TeamFoundation.Client.TeamFoundationServer($server, $NetCredentials) |
To begin with I instantiate the TeamFoundationServer object rather than calling GetService(). This is because I want to change the network credentials that I use to connect to the server (see Buck Hodges post on this).
>$workItemStore = [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore] >$store=$tfs.GetService($workItemStore) >$bug=$store.Projects["MSF for CMMI"].WorkItemTypes["Bug"].NewWorkItem() >$bug.Title="The application isn't working" >$bug.Save() Exception calling "Save" with "0" argument(s): "TF26201: This work item has unsupported fields, or user does not have permissions." |
The next problem was that saving the bug results in an error. I am pretty sure it is not permissions since I specified the credentials explicitly. This leaves the unsupported fields option (whatever that means). I check the Fields property and determine what the required fields are. After setting these fields I am able to store the bug. A non-zero ID and the revision number are just a few properties that verify the work item was successfully stored.
|
>$bug.Fields | where {$_.IsRequired -and (-not $_.IsValid)} | ft Name Name ---- Symptom Steps To Reproduce >$bug.Fields["Symptom"].Value="Headache" >$bug.Fields["Steps To Reproduce"].Value="Drink too much alcohol" >$bud.Save() >$bug.Id 183 >$store.GetWorkItem($bug.Id) Id : 183 Uri : vstfs:///WorkItemTracking/WorkItem/183 Revision : 1 Revisions : {Microsoft.TeamFoundation.WorkItemTracking.Client.Revision} Attachments : {} Links : {} Store : Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore Title : The application isn't working State : Proposed Reason : New Rev : 1 Description : History : ChangedBy : Mark Michaelis (Administrator) RevisedDate : 1/1/0001 12:00:00 AM ChangedDate : 9/26/2006 2:49:10 AM CreatedDate : 9/26/2006 2:49:10 AM CreatedBy : Mark Michaelis (Administrator) NodeName : MSF for CMMI AreaPath : MSF for CMMI AreaId : 153 IterationPath : MSF for CMMI IterationId : 153 ExternalLinkCount : 0 HyperLinkCount : 0 AttachedFileCount : 0 RelatedLinkCount : 0 IsOpen : True IsPartialOpen : False IsReadOnlyOpen : False Fields : {Title, State, Rev, Changed By...} Type : Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType Project : Microsoft.TeamFoundation.WorkItemTracking.Client.Project IsDirty : False DisplayForm : DisplayForm : <FORM> <...> </FORM> |
Just to make sure, I run a query for all active bugs to verify that mine is there.
>$store.Projects["MSF for CMMI"].StoredQueries | ft Name Active Bugs All My Team Project Work Items All Tasks All Work Items Blocked Work Items Change Requests Copy of Issues Corrective Actions Customer Requirements Development Tasks Issues Mitigation Action Status My Work Items Product Requirements Resolved Bugs Reviews Risks >$query=$store.Projects["MSF for CMMI"].StoredQueries | where{$_.Name -eq "Active Bugs"} >$store.Query($query.QueryText.Replace("@project", "'MSF for CMMI'")) ... |
One PowerShell question I couldn't find the answer on, is how do I enter a password without displaying it on the screen. The way RunAs works for example.
Tuesday, September 26, 2006 2:36:19 AM (Pacific Standard Time, UTC-08:00)
Computer Related | .Net | Headlines