Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Functions/AzureDevOps/Get-ADOField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
}

process {
if ($ApiVersion -like '5.*' -and $sr) {
Write-Warning "The API version '$ApiVersion' may not be compatible with field operations. Consider using '7.0' or later."
}

# First, construct a base URI. It's made up of:
$uriBase = "$Server".TrimEnd('/'), # * The server
$Organization, # * The organization
Expand Down
109 changes: 62 additions & 47 deletions Functions/AzureDevOps/Get-ADOPicklist.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function Get-ADOPicklist
{
function Get-ADOPicklist {
<#
.Synopsis
Gets picklists from Azure DevOps.
Expand All @@ -16,43 +15,43 @@
.Link
https://docs.microsoft.com/en-us/rest/api/azure/devops/processes/lists/get
#>
[OutputType('PSDevOps.Project','PSDevOps.Property')]
[CmdletBinding(DefaultParameterSetName='work/processes/lists')]
[OutputType('PSDevOps.Project', 'PSDevOps.Property')]
[CmdletBinding(DefaultParameterSetName = 'work/processes/lists')]
param(
# The Organization
[Parameter(Mandatory,ParameterSetName='work/processes/lists',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='work/processes/lists/{PickListID}',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='Orphan')]
[Alias('Org')]
[string]
$Organization,

# The Picklist Identifier.
[Parameter(Mandatory,ParameterSetName='work/processes/lists/{PickListID}',ValueFromPipelineByPropertyName)]
[string]
$PickListID,

# The name of the picklist
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$PicklistName = '*',

# If set, will return orphan picklists. These picklists are not associated with any field.
[Parameter(Mandatory,ParameterSetName='Orphan')]
[switch]
$Orphan,

# 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-preview.
# 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"
# The Organization
[Parameter(Mandatory, ParameterSetName = 'work/processes/lists', ValueFromPipelineByPropertyName)]
[Parameter(Mandatory, ParameterSetName = 'work/processes/lists/{PickListID}', ValueFromPipelineByPropertyName)]
[Parameter(Mandatory, ParameterSetName = 'Orphan')]
[Alias('Org')]
[string]
$Organization,

# The Picklist Identifier.
[Parameter(Mandatory, ParameterSetName = 'work/processes/lists/{PickListID}', ValueFromPipelineByPropertyName)]
[string]
$PickListID,

# The name of the picklist
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$PicklistName = '*',

# If set, will return orphan picklists. These picklists are not associated with any field.
[Parameter(Mandatory, ParameterSetName = 'Orphan')]
[switch]
$Orphan,

# 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-preview.
# 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 }
Expand All @@ -64,27 +63,43 @@
$q = [Collections.Queue]::new()
}
process {
if ($ApiVersion -like '5.*') {
Write-Warning "The API version '$ApiVersion' may not be compatible with field operations. Consider using '7.0' or later."
}

if ($Orphan) {
$allPicklists = Get-ADOPicklist -Organization $organization
$allUsedPicklists = Get-ADOField @invokeParams -Organization $Organization |
$allPicklists = @()
$allUsedPicklists = @()
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are initialized but then immediately reassigned in both branches of the if-else statement. The initialization is redundant and should be removed to improve code clarity.

Suggested change
$allUsedPicklists = @()

Copilot uses AI. Check for mistakes.
if ($Server -eq 'https://dev.azure.com') {
$allPicklists = Get-ADOPicklist -Organization $organization
$allUsedPicklists = Get-ADOField @invokeParams -Organization $Organization |
Where-Object { $_.IsPicklist } |
Select-Object -ExpandProperty PicklistID
}
else {
Write-Verbose "AzD Server currently is: $Server/$organization"
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected abbreviation from 'AzD' to 'ADO' to match the naming convention used throughout the codebase (Azure DevOps = ADO).

Suggested change
Write-Verbose "AzD Server currently is: $Server/$organization"
Write-Verbose "ADO Server currently is: $Server/$organization"

Copilot uses AI. Check for mistakes.
$allPicklists = Get-ADOPicklist -Organization $organization -Server $Server -Apiversion $apiVersion
$allUsedPicklists = Get-ADOField @invokeParams -Organization $Organization -Server $Server -Apiversion $apiVersion |
Where-Object { $_.IsPicklist } |
Select-Object -ExpandProperty PicklistID
}

$allPicklists |
Where-Object PicklistID -NotIn $allUsedPicklists
Where-Object PicklistID -NotIn $allUsedPicklists
return
}

$in = $_
$psParameterSet = $psCmdlet.ParameterSetName
$q.Enqueue(@{PSParameterSet=$psParameterSet} + $PSBoundParameters)
$q.Enqueue(@{PSParameterSet = $psParameterSet } + $PSBoundParameters)
}
end {
$c, $t, $progId = 0, $q.Count, [Random]::new().Next()
while ($q.Count) {
. $dq $q

$uri =
"$(@(
"$(@(
"$server".TrimEnd('/') # * The Server
$Organization
Expand All @@ -106,19 +121,19 @@


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

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

$additionalProperty = @{
Organization = $Organization
Server = $Server
Server = $Server
}
Invoke-ADORestAPI @invokeParams -uri $uri -PSTypeName "$Organization.$typeName",
"PSDevOps.$typeName" -Property $additionalProperty |
Where-Object { $_.Name -like $PicklistName }
"PSDevOps.$typeName" -Property $additionalProperty |
Where-Object { $_.Name -like $PicklistName }
}

Write-Progress "Getting" "[$t/$t]" -Completed -Id $progId
Expand Down
Loading