开发者

Programatically delete [permenantly] a TFS work item

Whilst I'm aware that there is a command line tool to permenantly delete a TFS work item. (e.g. How to delete Work Item from 开发者_运维知识库Team Foundation Server)

Has anyone been able to achieve the same action programatically using the TFS 2010 API DLLs?


Shai Raiten has blogged about this here, where he makes use of DestroyWorkItems(ids).

It is advisable that you proceed with extra caution in your implementation, since this can severely mess your installation. One could argue that constructing such a tool deviates from best practices.


You can also use PowerShell to bulk delete work items:

Copy and paste below script in a PowerShell file (with .ps1 extension), update the variable values mentioned in the list #4 below and run the command from a machine where witadmin tool is installed (Generally available after visual studio installation). Open PowerShell command window and execute the script. Note: Account running below script should have team foundation administrator or collection administrator access.

########TFS Work Items Bulk Destroy Automation Script##########
#Notes:
#1) This script requires to setup file/folder path, validate the file/folders path before running the script
#2) start the powershell window as Administrator and run the script
#3) This script requires share and admin access on the destination server, make sure your account or the account under which script is
#    executing is member of admin group on the destination server
#4) Update following:
#   4.1: $CollectionURL
#   4.2: $WitAdmin tool location
        # For VS 2015, Default location is C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
        # For VS 2013, Default location is C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE
#   4.3: $WI_List
#   4.4: $logfile
####################

$CollectionURL = "http://tfs:8080/tfs/CollectionName"
$WitAdminLocation = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"
$WI_List =  Get-Content "C:\WI_List.txt"
$logfile="C:\log.txt"
$ExecutionStartTime = Get-Date
$WICount = 0
"## Starting WI Destroy @ $ExecutionStartTime ##"| Out-File $logfile -Append
"Collection URL: $CollectionURL" | Out-File $logfile -Append
foreach ($WIID in $WI_List)
    {
        CD $WitAdminLocation
        .\witadmin destroywi /collection:$CollectionURL /id:$WIID /noprompt
        "WI ID: $WIID Destroyed" | Out-File $logfile -Append
        $WICount = $WICount + 1
        Write-Host "$WICount Work Items Deleted"
    }

$ExecutionEndTime = Get-Date
"## WI Destroy Command Completed @ $ExecutionEndTime ##"| Out-File $logfile -Append

$TotalExecutionTime = $ExecutionEndTime - $ExecutionStartTime

"Total Work Items Deleted: $WICount"   | Out-File $logfile -Append

" Total Execution Time: $TotalExecutionTime"  | Out-File $logfile -Append

##End of script##
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜