public/Build-SfGlobalValueSetMetadata.ps1

function Build-SfGlobalValueSetMetadata {

    <#
        .SYNOPSIS
        Builds the *.globalValueSet-meta.xml files from the metadata model.

        .DESCRIPTION
        Processes the global value sets as given in table [_GlobalValueSets] in the metadata model.
        The picklist values will be collected from table [_PicklistValues] in the metadata model.

        .LINK
        Build-SfGlobalValueSetMetadataTranslation

        .LINK
        Import-SfMetadataModel

        .LINK
        https://codeberg.org/uwe-braig/sf-metadata-toolkit
    #>


    [CmdletBinding()]
    param (
        # The metadata model as imported from *.csv and/or *.xlsx with Import-SfMetadataModel
        [Parameter(Mandatory, Position = 0)]
        [PSCustomObject] $MetadataModel,

        # List of names of the GlobalValueSet to be built. If left empty, all will be built.
        [Parameter()]
        [string[]] $ValueSetNames,

        # Target path for the resulting *.xml files. Default is [./force-app/main/default].
        [Parameter()]
        [string] $TargetPath = './force-app/main/default'
    )

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

    # --- prepare target directories
    $GlobalValueSetPath = Join-Path $TargetPath 'globalValueSets'
    $GlobalValueSetDirectory = New-Item -ItemType Directory -Path $GlobalValueSetPath -Force
    Write-Debug "Writing to: $($GlobalValueSetDirectory.FullName)"

    # --- build the global value sets, but only those that match the filter
    foreach ($ValueSet in $MetadataModel.Tables._GlobalValueSets) {
        if (
            (!$ValueSetNames) -or
            ($ValueSetNames -contains $ValueSet._Name) -or
            ($ValueSetNames -contains "GlobalValueSet:$($ValueSet._Name)")
            ) {

            $xmlString = ConvertTo-SfGlobalValueSetXml -ValueSet $ValueSet -PicklistValues $MetadataModel.Tables._PicklistValues
            Set-MetadataXmlFile 'GlobalValueSet' $ValueSet._Name '.globalValueSet-meta.xml' $GlobalValueSetPath $xmlString
        }
    }
}