functions/update-adoprocessbehavior.ps1
<# .SYNOPSIS Updates a behavior in the process. .DESCRIPTION This function uses the `Invoke-ADOApiRequest` function to call the Azure DevOps REST API and update a specific behavior for a specified process. .PARAMETER Organization The name of the Azure DevOps organization. .PARAMETER Token The authentication token for accessing Azure DevOps. .PARAMETER ProcessId The ID of the process. .PARAMETER BehaviorRefName The reference name of the behavior. .PARAMETER Body The JSON string containing the properties for the behavior to update. .PARAMETER ApiVersion The version of the Azure DevOps REST API to use. Default is "7.1". .EXAMPLE $body = @" { "name": "NewCustomBehavior", "color": "FFFABC" } "@ Update-ADOProcessBehavior -Organization "fabrikam" -Token "my-token" -ProcessId "906c7065-2a04-4f61-aac1-b5da9cef040b" -BehaviorRefName "Custom.4b8fdba0-7064-458d-b55c-522b39059a62" -Body $body Updates the specified behavior for the process. .NOTES This function follows PSFramework best practices for logging and error handling. Author: Oleksandr Nikolaiev (@onikolaiev) #> function Update-ADOProcessBehavior { [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$Organization, [Parameter(Mandatory = $true)] [string]$Token, [Parameter(Mandatory = $true)] [string]$ProcessId, [Parameter(Mandatory = $true)] [string]$BehaviorRefName, [Parameter(Mandatory = $true)] [string]$Body, [Parameter()] [string]$ApiVersion = $Script:ADOApiVersion ) begin { Invoke-TimeSignal -Start # Log the start of the operation Write-PSFMessage -Level Verbose -Message "Starting update of behavior '$BehaviorRefName' for ProcessId: $ProcessId in Organization: $Organization" } process { if (Test-PSFFunctionInterrupt) { return } try { # Build the API URI $apiUri = "_apis/work/processes/$ProcessId/behaviors/$BehaviorRefName" # Log the request details Write-PSFMessage -Level Verbose -Message "API URI: $apiUri" Write-PSFMessage -Level Verbose -Message "Request Body: $Body" # Call the Invoke-ADOApiRequest function $response = Invoke-ADOApiRequest -Organization $Organization ` -Token $Token ` -ApiUri $apiUri ` -Method "PUT" ` -Body $Body ` -Headers @{"Content-Type" = "application/json"} ` -ApiVersion $ApiVersion # Log the successful response Write-PSFMessage -Level Verbose -Message "Successfully updated behavior '$BehaviorRefName' for ProcessId: $ProcessId" return $response.Results | Select-PSFObject * -TypeName "ADO.CORE.ProcessBehaviorObject" } catch { # Log the error Write-PSFMessage -Level Error -Message "Failed to update behavior: $($_.ErrorDetails.Message)" -Exception $PSItem.Exception Stop-PSFFunction -Message "Stopping because of errors" return } } end { # Log the end of the operation Write-PSFMessage -Level Verbose -Message "Completed update of behavior '$BehaviorRefName' for ProcessId: $ProcessId" Invoke-TimeSignal -End } } |