forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADOWorkProcess.ps1
97 lines (86 loc) · 4.1 KB
/
Get-ADOWorkProcess.ps1
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
90
91
92
93
94
95
96
97
function Get-ADOWorkProcess
{
<#
.Synopsis
Gets work processes from ADO.
.Description
Gets work processes from Azure DevOps.
.Link
https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/processes/list?view=azure-devops-rest-5.1
.Example
Get-ADOWorkProcess -Organization StartAutomating -PersonalAccessToken $pat
.Example
Get-ADOProject -Organization StartAutomating -PersonalAccessToken $pat | Get-ADOWorkProcess
#>
[CmdletBinding(DefaultParameterSetName='/{Organization}/_apis/work/processes')]
[OutputType('PSDevOps.WorkProcess')]
param(
# The Organization
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('Org')]
[string]
$Organization,
# The Project Identifier. If this is provided, will get the work process associated with that project.
[Parameter(Mandatory,ValueFromPipelineByPropertyName,
ParameterSetName='/{Organization}/_apis/projects/{ProjectID}/properties')]
[string]
$ProjectID,
# The process identifier
[Parameter(Mandatory,ParameterSetName='/{Organization}/_apis/work/processes/{ProcessId}',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Organization}/_apis/work/processes/{ProcessId}/workItemTypes',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Organization}/_apis/work/processes/{ProcessId}/behaviors',ValueFromPipelineByPropertyName)]
[Alias('TypeID')]
[string]
$ProcessID,
# If set, will list work item types in a given Work process.
[Parameter(Mandatory,ParameterSetName='/{Organization}/_apis/work/processes/{ProcessId}/workItemTypes',ValueFromPipelineByPropertyName)]
[Alias('WorkItemTypes')]
[switch]
$WorkItemType,
# If set, will list behaviors associated with a given work process.
[Parameter(Mandatory,ParameterSetName='/{Organization}/_apis/work/processes/{ProcessId}/behaviors',ValueFromPipelineByPropertyName)]
[Alias('Behaviors')]
[switch]
$Behavior,
# The server. By default https://dev.azure.com/.
# To use against TFS, provide the tfs server URL (e.g. http://tfsserver:8080/tfs).
[Parameter(ValueFromPipelineByPropertyName)]
[uri]
$Server = "https://dev.azure.com/",
# The api version. By default, 5.1.
# If targeting TFS, this will need to change to match your server version.
# See: https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops
[string]
$ApiVersion = "5.1-preview")
dynamicParam { . $GetInvokeParameters -DynamicParameter }
begin {
#region Copy Invoke-ADORestAPI parameters
$invokeParams = . $getInvokeParameters $PSBoundParameters
#endregion Copy Invoke-ADORestAPI parameters
}
process {
$psParameterSet = $psCmdlet.ParameterSetName
if ($psParameterSet -eq '/{Organization}/_apis/projects/{ProjectID}/properties')
{
$processId =
Get-ADOProject -Organization $Organization -ProjectID $ProjectID -Metadata @invokeParams -Server $Server |
Where-Object Name -EQ System.ProcessTemplateType |
Select-Object -ExpandProperty Value
$psParameterSet = $MyInvocation.MyCommand.Parameters['ProcessID'].ParameterSets.Keys |
Sort-Object Length |
Select-Object -First 1
}
$uri = "$Server".TrimEnd('/') + (. $ReplaceRouteParameter $psParameterSet) + '?'
if ($ApiVersion) {
$uri += "api-version=$ApiVersion"
}
$typeName = @($psParameterSet -split '/')[-1].TrimEnd('s') -replace
'processe$', 'WorkProcess' -replace
'\{ProcessId\}', 'WorkProcess'
$addProperty = @{Organization=$Organization; Server = $Server}
if ($ProcessID) {
$addProperty['ProcessID'] = $ProcessID
}
Invoke-ADORestAPI @invokeParams -uri $uri -PSTypeName "$Organization.$typeName", "PSDevOps.$typeName" -Property $addProperty
}
}