Skip to content

Commit d9b6eb8

Browse files
Nico OrschelNico Orschel
authored andcommitted
Add API version compatibility warning and fix find orphan picklists in Get-ADOPicklist for AzD Server
1 parent df15e78 commit d9b6eb8

File tree

2 files changed

+62
-47
lines changed

2 files changed

+62
-47
lines changed

Functions/AzureDevOps/Get-ADOField.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
}
7777

7878
process {
79+
if ($ApiVersion -like '5.*' -and $sr) {
80+
Write-Warning "The API version '$ApiVersion' may not be compatible with field operations. Consider using '7.0' or later."
81+
}
82+
7983
# First, construct a base URI. It's made up of:
8084
$uriBase = "$Server".TrimEnd('/'), # * The server
8185
$Organization, # * The organization

Functions/AzureDevOps/Get-ADOPicklist.ps1

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
function Get-ADOPicklist
2-
{
1+
function Get-ADOPicklist {
32
<#
43
.Synopsis
54
Gets picklists from Azure DevOps.
@@ -16,43 +15,43 @@
1615
.Link
1716
https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/lists/get
1817
#>
19-
[OutputType('PSDevOps.Project','PSDevOps.Property')]
20-
[CmdletBinding(DefaultParameterSetName='work/processes/lists')]
18+
[OutputType('PSDevOps.Project', 'PSDevOps.Property')]
19+
[CmdletBinding(DefaultParameterSetName = 'work/processes/lists')]
2120
param(
22-
# The Organization
23-
[Parameter(Mandatory,ParameterSetName='work/processes/lists',ValueFromPipelineByPropertyName)]
24-
[Parameter(Mandatory,ParameterSetName='work/processes/lists/{PickListID}',ValueFromPipelineByPropertyName)]
25-
[Parameter(Mandatory,ParameterSetName='Orphan')]
26-
[Alias('Org')]
27-
[string]
28-
$Organization,
29-
30-
# The Picklist Identifier.
31-
[Parameter(Mandatory,ParameterSetName='work/processes/lists/{PickListID}',ValueFromPipelineByPropertyName)]
32-
[string]
33-
$PickListID,
34-
35-
# The name of the picklist
36-
[Parameter(ValueFromPipelineByPropertyName)]
37-
[string]
38-
$PicklistName = '*',
39-
40-
# If set, will return orphan picklists. These picklists are not associated with any field.
41-
[Parameter(Mandatory,ParameterSetName='Orphan')]
42-
[switch]
43-
$Orphan,
44-
45-
# The server. By default https://dev.azure.com/.
46-
# To use against TFS, provide the tfs server URL (e.g. http://tfsserver:8080/tfs).
47-
[Parameter(ValueFromPipelineByPropertyName)]
48-
[uri]
49-
$Server = "https://dev.azure.com/",
50-
51-
# The api version. By default, 5.1-preview.
52-
# If targeting TFS, this will need to change to match your server version.
53-
# See: https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops
54-
[string]
55-
$ApiVersion = "5.1-preview"
21+
# The Organization
22+
[Parameter(Mandatory, ParameterSetName = 'work/processes/lists', ValueFromPipelineByPropertyName)]
23+
[Parameter(Mandatory, ParameterSetName = 'work/processes/lists/{PickListID}', ValueFromPipelineByPropertyName)]
24+
[Parameter(Mandatory, ParameterSetName = 'Orphan')]
25+
[Alias('Org')]
26+
[string]
27+
$Organization,
28+
29+
# The Picklist Identifier.
30+
[Parameter(Mandatory, ParameterSetName = 'work/processes/lists/{PickListID}', ValueFromPipelineByPropertyName)]
31+
[string]
32+
$PickListID,
33+
34+
# The name of the picklist
35+
[Parameter(ValueFromPipelineByPropertyName)]
36+
[string]
37+
$PicklistName = '*',
38+
39+
# If set, will return orphan picklists. These picklists are not associated with any field.
40+
[Parameter(Mandatory, ParameterSetName = 'Orphan')]
41+
[switch]
42+
$Orphan,
43+
44+
# The server. By default https://dev.azure.com/.
45+
# To use against TFS, provide the tfs server URL (e.g. http://tfsserver:8080/tfs).
46+
[Parameter(ValueFromPipelineByPropertyName)]
47+
[uri]
48+
$Server = "https://dev.azure.com/",
49+
50+
# The api version. By default, 5.1-preview.
51+
# If targeting TFS, this will need to change to match your server version.
52+
# See: https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops
53+
[string]
54+
$ApiVersion = "5.1-preview"
5655
)
5756

5857
dynamicParam { . $GetInvokeParameters -DynamicParameter }
@@ -65,26 +64,38 @@
6564
}
6665
process {
6766
if ($Orphan) {
68-
$allPicklists = Get-ADOPicklist -Organization $organization
69-
$allUsedPicklists = Get-ADOField @invokeParams -Organization $Organization |
67+
$allPicklists = @()
68+
$allUsedPicklists = @()
69+
if ($Server -eq 'https://dev.azure.com') {
70+
$allPicklists = Get-ADOPicklist -Organization $organization
71+
$allUsedPicklists = Get-ADOField @invokeParams -Organization $Organization |
7072
Where-Object { $_.IsPicklist } |
7173
Select-Object -ExpandProperty PicklistID
74+
}
75+
else {
76+
Write-Verbose "AzD Server currently is: $Server/$organization"
77+
$allPicklists = Get-ADOPicklist -Organization $organization -Server $Server -Apiversion $apiVersion
78+
$allUsedPicklists = Get-ADOField @invokeParams -Organization $Organization -Server $Server -Apiversion $apiVersion |
79+
Where-Object { $_.IsPicklist } |
80+
Select-Object -ExpandProperty PicklistID
81+
}
82+
7283
$allPicklists |
73-
Where-Object PicklistID -NotIn $allUsedPicklists
84+
Where-Object PicklistID -NotIn $allUsedPicklists
7485
return
7586
}
7687

7788
$in = $_
7889
$psParameterSet = $psCmdlet.ParameterSetName
79-
$q.Enqueue(@{PSParameterSet=$psParameterSet} + $PSBoundParameters)
90+
$q.Enqueue(@{PSParameterSet = $psParameterSet } + $PSBoundParameters)
8091
}
8192
end {
8293
$c, $t, $progId = 0, $q.Count, [Random]::new().Next()
8394
while ($q.Count) {
8495
. $dq $q
8596

8697
$uri =
87-
"$(@(
98+
"$(@(
8899
89100
"$server".TrimEnd('/') # * The Server
90101
$Organization
@@ -106,19 +117,19 @@
106117

107118

108119
$typeName = @($psParameterSet -split '/' -notlike '{*}')[-1] -replace
109-
's$', '' -replace 'list', 'Picklist'
120+
's$', '' -replace 'list', 'Picklist'
110121

111122
if ($psParameterSet -like '*/{PicklistId}') {
112123
$typeName = "PickList.Detail"
113124
}
114125

115126
$additionalProperty = @{
116127
Organization = $Organization
117-
Server = $Server
128+
Server = $Server
118129
}
119130
Invoke-ADORestAPI @invokeParams -uri $uri -PSTypeName "$Organization.$typeName",
120-
"PSDevOps.$typeName" -Property $additionalProperty |
121-
Where-Object { $_.Name -like $PicklistName }
131+
"PSDevOps.$typeName" -Property $additionalProperty |
132+
Where-Object { $_.Name -like $PicklistName }
122133
}
123134

124135
Write-Progress "Getting" "[$t/$t]" -Completed -Id $progId

0 commit comments

Comments
 (0)