I have a function that receives a parameter which contains the file it should work on ($archivo). That same value should be passed on to another function that is called within the same function. But for some reason on the second function I'm getting a blank value.
function EXTRAER_DATA_COMIDA_Y_CREAR_WORD ($archivo) {
    
    write-host "EXTRAER_DATA_COMIDA" -foreground green
    $FILE = Join-Path -Path $root\UNB\FACTURA_FINAL\ -ChildPath $archivo
    $result = switch -Regex -File $FILE {
        '^([\d,.]+)\s+([\w\s]+)\s+([\d,.]+)' { 
            [PsCustomObject]@{
                Quantity = $matches[1].Trim()
                Product  = $matches[2].Trim()
                Price    = $matches[3].Trim()
            }
        }
    }
    
     ,$result
     CREAR_DOCWORD($result,$archivo)
    
} 
Which is the correct way to do it?
Thanks in advance !
EDIT: This is the new code as far as I can go
$results =function EXTRAER_DATA_COMIDA_Y_CREAR_WORD($archivo) 
{
write-host "EXTRAER_DATA_COMIDA" -fore green
$FILE = Join-Path -Path $root\UNB\FACTURA_FINAL\ -ChildPath $archivo
$result = switch -Regex -File $FILE {
    '^([\d,.]+)\s+([\w\s]+)\s+([\d,.]+)' { 
        [PsCustomObject]@{
            Quantity = $matches[1].Trim()
            Product  = $matches[2].Trim()
            Price    = $matches[3].Trim()
        }
    }
}
 ,@($result)
 Write-Host "variables que entran a docword" $results $results.GetType() $archivo
 CREAR_DOCWORD $results $archivo
}
FUNCTION CREAR_DOCWORD($COMIDA,$archivo) {
$objWord = New-Object -ComObject word.application
$objWord.Visible = $True
$Path = "$root\UNB\script\Tiquete_UnBilling.docx"
$objDoc = $objWord.Documents.Open("$Path")
$objSelection = $objWord.Selection
Write-Host "variables docword" $COMIDA $COMIDA.GetType() $archivo
   
    ## ESTA FUNCION CREA LA TABLA CON LOS DATOS DE COMIDA
    Write-Host "TAMAÑO ARRAY" $COMIDA.Length
    Write-Host "NOMBRE ARCHIVO" $archivo
    $table = $objDoc.Tables(1)
    
    for ($i=0; $i -le $comida.Count; $i++){
    Write-Host "contador" $i
    $table.rows.add() | out-null
    $table.cell(($i+2),1).Range.Text = $comida[$i].Quantity
    $table.cell(($i+2),2).Range.Text = $comida[$i].Product
    $table.cell(($i+2),3).Range.Text = $comida[$i].Price
    }
}
Even using ,@($result) I get a type object that looks like System.Management.Automation.PSCustomObject so it cant be use in the for loop because it has no size.
 
    