TFSPowershell.Workitems.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#Assemblies folder for TFS Object Model Client
$rootPath = $PSScriptRoot
$AssembliesDir = "$rootPath\Assemblies"

Add-Type -Path  "$AssembliesDir\Microsoft.IdentityModel.Clients.ActiveDirectory.dll",
                "$AssembliesDir\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll",                           
                "$AssembliesDir\Microsoft.ServiceBus.dll",
                "$AssembliesDir\Microsoft.TeamFoundation.Client.dll",                   
                "$AssembliesDir\Microsoft.TeamFoundation.Common.dll",                   
                "$AssembliesDir\Microsoft.TeamFoundation.Controls.dll",                 
                "$AssembliesDir\Microsoft.TeamFoundation.Core.WebApi.dll",              
                "$AssembliesDir\Microsoft.TeamFoundation.Diff.dll",                    
                "$AssembliesDir\Microsoft.TeamFoundation.Sync.Mapping.dll",             
                "$AssembliesDir\Microsoft.TeamFoundation.Sync.Project.Server.Library.dll",                                                    
                "$AssembliesDir\Microsoft.TeamFoundation.Sync.ProjectServerApi.dll",    
                "$AssembliesDir\Microsoft.TeamFoundation.Sync.Shared.dll",              
                "$AssembliesDir\Microsoft.TeamFoundation.VersionControl.Client.dll",    
                "$AssembliesDir\Microsoft.TeamFoundation.VersionControl.Common.dll",    
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll",                                        
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.Client.dll",  
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll",                                          
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.Common.dll",  
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.Controls.dll",
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.ControlsCore.dll",                                                  
                "$AssembliesDir\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll" ,  
                "$AssembliesDir\Microsoft.VisualStudio.Services.Client.dll",            
                "$AssembliesDir\Microsoft.VisualStudio.Services.Common.dll",            
                "$AssembliesDir\Microsoft.VisualStudio.Services.WebApi.dll",                                                          
                "$AssembliesDir\Newtonsoft.Json.dll",                                   
                "$AssembliesDir\System.Net.Http.Formatting.dll"

# .ExternalHelp .\MAML\TFSPowershell.Workitems.Help.xml
Function Get-WorkItemById
{
    [CmdletBinding()]
    Param (
        [string] $CollectionUrl,

        [Parameter(mandatory=$true)]
        [int] $WorkitemId,

        [Parameter(ValueFromPipeline=$True)]
        [Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]$Tfs = $null
    )

    if ($Tfs -eq $null)
    {
        $Tfs = Get-TeamProjectCollection -CollectionUrl $CollectionUrl
    }
  
    $workItemStore = $Tfs.GetService("Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
    Write-Output $workItemStore.GetWorkItem($WorkitemId);
}

# .ExternalHelp .\MAML\TFSPowershell.Workitems.Help.xml
Function Update-WorkItemField
{ 
    Write-Warning "Function not yet implemented!!"
}

# .ExternalHelp .\MAML\TFSPowershell.Workitems.Help.xml
Function Destroy-WorkItemById
{
    [CmdletBinding()]
    Param (
        [string] $CollectionUrl,

        [Parameter(mandatory=$true)]
        [int] $WorkitemId,

        [Parameter(ValueFromPipeline=$True)]
        [Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]$Tfs = $null
    )


    if ($Tfs -eq $null)
    {
        Write-Verbose "Connecting to TFS..."
        $Tfs = Get-TeamProjectCollection -CollectionUrl $CollectionUrl
    }
    
    Write-Verbose "Destroying the Workitem $WorkitemId..."
    $workItemStore = $Tfs.GetService("Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
    $workItems = New-Object Collections.Generic.List[int]
    $workItems.Add($WorkitemId)
    $workItemStore.DestroyWorkItems($workItems)
    Write-Verbose "Done!"
}