|
1 | | -function Get-ADOPicklist |
2 | | -{ |
| 1 | +function Get-ADOPicklist { |
3 | 2 | <# |
4 | 3 | .Synopsis |
5 | 4 | Gets picklists from Azure DevOps. |
|
16 | 15 | .Link |
17 | 16 | https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/lists/get |
18 | 17 | #> |
19 | | - [OutputType('PSDevOps.Project','PSDevOps.Property')] |
20 | | - [CmdletBinding(DefaultParameterSetName='work/processes/lists')] |
| 18 | + [OutputType('PSDevOps.Project', 'PSDevOps.Property')] |
| 19 | + [CmdletBinding(DefaultParameterSetName = 'work/processes/lists')] |
21 | 20 | 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" |
56 | 55 | ) |
57 | 56 |
|
58 | 57 | dynamicParam { . $GetInvokeParameters -DynamicParameter } |
|
65 | 64 | } |
66 | 65 | process { |
67 | 66 | 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 | |
70 | 72 | Where-Object { $_.IsPicklist } | |
71 | 73 | 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 | + |
72 | 83 | $allPicklists | |
73 | | - Where-Object PicklistID -NotIn $allUsedPicklists |
| 84 | + Where-Object PicklistID -NotIn $allUsedPicklists |
74 | 85 | return |
75 | 86 | } |
76 | 87 |
|
77 | 88 | $in = $_ |
78 | 89 | $psParameterSet = $psCmdlet.ParameterSetName |
79 | | - $q.Enqueue(@{PSParameterSet=$psParameterSet} + $PSBoundParameters) |
| 90 | + $q.Enqueue(@{PSParameterSet = $psParameterSet } + $PSBoundParameters) |
80 | 91 | } |
81 | 92 | end { |
82 | 93 | $c, $t, $progId = 0, $q.Count, [Random]::new().Next() |
83 | 94 | while ($q.Count) { |
84 | 95 | . $dq $q |
85 | 96 |
|
86 | 97 | $uri = |
87 | | - "$(@( |
| 98 | + "$(@( |
88 | 99 |
|
89 | 100 | "$server".TrimEnd('/') # * The Server |
90 | 101 | $Organization |
|
106 | 117 |
|
107 | 118 |
|
108 | 119 | $typeName = @($psParameterSet -split '/' -notlike '{*}')[-1] -replace |
109 | | - 's$', '' -replace 'list', 'Picklist' |
| 120 | + 's$', '' -replace 'list', 'Picklist' |
110 | 121 |
|
111 | 122 | if ($psParameterSet -like '*/{PicklistId}') { |
112 | 123 | $typeName = "PickList.Detail" |
113 | 124 | } |
114 | 125 |
|
115 | 126 | $additionalProperty = @{ |
116 | 127 | Organization = $Organization |
117 | | - Server = $Server |
| 128 | + Server = $Server |
118 | 129 | } |
119 | 130 | 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 } |
122 | 133 | } |
123 | 134 |
|
124 | 135 | Write-Progress "Getting" "[$t/$t]" -Completed -Id $progId |
|
0 commit comments