Public/Set/Set-HaloOpportunity.ps1

Function Set-HaloOpportunity {
    <#
        .SYNOPSIS
            Updates one or more opportunities via the Halo API.
        .DESCRIPTION
            Function to send an opportunity update request to the Halo API
        .OUTPUTS
            Outputs an object containing the response from the web request.
    #>

    [CmdletBinding( SupportsShouldProcess = $True )]
    [OutputType([Object[]])]
    Param (
        # Object or array of objects containing properties and values used to update one or more existing opportunities.
        [Parameter( Mandatory = $True, ValueFromPipeline )]
        [Object[]]$Opportunity
    )
    Invoke-HaloPreFlightCheck
    try {
        $ObjectToUpdate = $Opportunity | ForEach-Object {
            $HaloOpportunityParams = @{
                OpportunityId = $_.id
            }
            $OpportunityExists = Get-HaloOpportunity @HaloOpportunityParams
            if ($OpportunityExists) {
                Return $True
            } else {
                Return $False
            }
        }
        if ($False -notin $ObjectToUpdate) {
            if ($PSCmdlet.ShouldProcess($Opportunity -is [Array] ? 'Opportunities' : 'Opportunity', 'Update')) {
                New-HaloPOSTRequest -Object $Opportunity -Endpoint 'opportunities' -Update
            }
        } else {
            Throw 'One or more opportunities was not found in Halo to update.'
        }
    } catch {
        New-HaloError -ErrorRecord $_
    }
}