forked from kine/NVRAppDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-BatchWI.ps1
62 lines (57 loc) · 2.25 KB
/
Get-BatchWI.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
<#
.SYNOPSIS
Get Work Items in batch
.DESCRIPTION
Read the work item from Azure DevOps
.Parameter accountName
Name of the Azure DevOps organization to use
.Parameter PAT
PAT to use when connecting to Azure DevOps
.Parameter OAuthToken
OAuthToken to use for athentication (e.g. System.AccessToken from build agent)
.Parameter WINos
Numbers of the Work Items
.Parameter Expand
Value for API parameter $expand (None, Relations, Fields, Links, All)
.OUTPUTS
return work items data
#>
function Get-BatchWI
{
param(
[Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True,ParameterSetName='WINo')]
[string]$accountName,
[Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True,ParameterSetName='WINo')]
[string]$projectName,
[Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True,ParameterSetName='ADOUrl')]
[string]$ADOUrl,
[Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True)]
[int[]]$WINos,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[string]$PAT,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[string]$OAuthToken='',
[Parameter(ValueFromPipelineByPropertyName=$True)]
[ValidateSet('None', 'Relations', 'Fields', 'Links', 'All')]
$Expand='None'
)
$ErrorActionPreference = "Stop"
$Token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
if (-not $OAuthToken) {
Write-Verbose -Message 'PAT authorization used'
$Header = @{"Authorization" = "Basic "+$Token; "content-type" = "application/json"}
} else {
Write-Verbose -Message 'OAuth authorization used'
$Header = @{"Authorization" = "Bearer "+$OAuthToken; "content-type" = "application/json"}
}
if ($ADOUrl) {
$requestUri = "$ADOUrl/_apis/wit/workitemsbatch?api-version=5.1"
} else {
$requestUri = "https://dev.azure.com/$accountName/$projectName/_apis/wit/workitemsbatch?api-version=5.1"
}
$body=@{'$expand'=$Expand;'ids'=$WINos}
Write-Verbose -Message $requestUri
Write-Verbose -Message ($body|ConvertTo-Json)
$response = Invoke-RestMethod -Uri $requestUri -Method Post -Body ($body|ConvertTo-Json) -Headers $Header -Verbose
Return $response
}