Home > Net >  Create task un TFS via PowerShell
Create task un TFS via PowerShell

Time:02-25

I need to create a task under my project. I find some code that should work. It fails in $store.Projects[0].WorkItemTypes[0]) How can I know what the project ID and WorkItemTypes? Maybe there is a different solution for this? When I run like this i am getting this error: Exception calling "Save" with "0" argument(s): "TF237111: The current user does not have permissions to save work items under the specified area path."

I managed to connect by replacing the ID with a string. Item type could be task $workitem.[‘task’] I need to create the task under as link item but don’t know how

$key = Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0

$dir = [string] (Get-ItemProperty $key.InstallDir)

$dir  = "Extensions\ymj51wgi.3ie\"

$lib = $dir   "Microsoft.TeamFoundation.WorkItemTracking.Client.dll"

[Reflection.Assembly]::LoadFrom($lib)

$lib = $dir   "Microsoft.TeamFoundation.Client.dll"

[Reflection.Assembly]::LoadFrom($lib)

#"Please enter your Team Foundation Server Name:"
#$server = [Console]::ReadLine()
#$server = $server.Trim()

#"Connecting to "   $server   "..."
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer("https://tfs.XXXXX.com/DefaultCollection")

$type = [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore]

$store = [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore] $tfs.GetService($type)

$workItem = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem($store.Projects[0].WorkItemTypes[0])

"Created a new work item of type "   $workItem.Type.Name

$workItem.Title = "Created by Windows PowerShell!"

$workItem.Save()

CodePudding user response:

Have you looked into VSTeam? A PowerShell module for many features in TFS / Azure DevOps.

Set-VSTeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication
Set-VSTeamDefaultProject Demo
Add-VSTeamWorkItem -Title "New Work Item" -WorkItemType Task

ID Title          Status
-- -----          ------
6  New Work Item  To Do
  • Related