private/ConvertTo-SfPicklistValueXml.ps1

function ConvertTo-SfPicklistValueXml {

    [CmdletBinding()]
    param (
        [Parameter(Mandatory, Position=0)]
        [pscustomobject] $PicklistValue
    )

    $ErrorActionPreference = 'Stop'
    [bool] $IsDebug   = $DebugPreference   -ne 'SilentlyContinue'
    [bool] $IsVerbose = $VerbosePreference -ne 'SilentlyContinue'

    $ValueSetKey = "$($PicklistValue._ValueSetType):$($PicklistValue._ValueSetName)"

    # --- different value tag names per value set type
    $TagName = switch ($PicklistValue._ValueSetType) {
        'FieldValueSet'     { 'value' }
        'GlobalValueSet'    { 'customValue' }
        'StandardValueSet'  { 'standardValue' }
        Default             { '' }
    }

    $xml = "<$TagName>"
    $xml += ConvertTo-XmlTag 'fullName' $PicklistValue._ApiValue

    # --- default?
    $xml += switch ($PicklistValue._Flags) {
        'X+D+C' { '<default>true</default>' }
        'X+D'   { '<default>true</default>' }
        Default { '<default>false</default>' }
    }

    # --- OpportunityStage
    if ($ValueSetKey -eq 'StandardValueSet:OpportunityStage') {
        $xml += ConvertTo-XmlTag 'description' $PicklistValue._Description 'Xml'
    }

    # --- active?
    $xml += switch ($PicklistValue._Flags) {
        '-'     { '<isActive>false</isActive>' }
        '--'    { '<isActive>false</isActive>' }
        Default { '' }
    }

    # --- picklist label, use API value as fallback if no label is given.
    # Note: '' instead of $null is to be guaranteed by the caller/the importer
    if ($PicklistValue._Label -eq '') {
        $xml += ConvertTo-XmlTag 'label' $PicklistValue._ApiValue
    } else {
        $xml += ConvertTo-XmlTag 'label' $PicklistValue._Label
    }

    # --- LeadStatus: special handling '+C'
    if ($ValueSetKey -eq 'StandardValueSet:LeadStatus') {
        $xml += switch ($PicklistValue._ConvertedStatus) {
            'X'     { '<converted>true</converted>' }
            Default { '<converted>false</converted>' }
        }
    }

    # --- OpportunityStage
    if ($ValueSetKey -eq 'StandardValueSet:OpportunityStage') {
        $xml += switch ($PicklistValue._ClosedStatus) {
            'ClosedWon'     { '<closed>true</closed>' }
            'ClosedLost'    { '<closed>true</closed>' }
            Default         { '<closed>false</closed>' }
        }
        $xml += ConvertTo-XmlTag 'forecastCategory' $PicklistValue._ForecastCategory
        $xml += ConvertTo-XmlTag 'probability' $PicklistValue._Probability
        $xml += switch ($PicklistValue._ClosedStatus) {
            'ClosedWon'     { '<won>true</won>' }
            Default         { '<won>false</won>' }
        }
    }

    # --- CaseStatus: special handling '+C'
    if ($ValueSetKey -eq 'StandardValueSet:CaseStatus') {
        $xml += switch ($PicklistValue._Flags) {
            'X+D+C' { '<closed>true</closed>' }
            'X+C'   { '<closed>true</closed>' }
            Default { '<closed>false</closed>' }
        }
    }

    $xml += "</$TagName>"

    return $xml
}