1

I declared an array of tuples as follows:

 [System.Tuple[string,string][]] $files = @()

And I have the following workflow:

Workflow Perform-Download
{
    Param (
        [Parameter(Mandatory = $true)]
        [System.Tuple[string,string][]] $Files
    )
    ForEach -Parallel ($file in $Files)
    {
        Parallel{Save-File -Url $file.Item1 -DestinationFolder $file.Item2}
    }
}

I'm trying to do the following:

Perform-Download -Files $files

But I get the following error:

Perform-Download : Cannot process argument transformation on parameter 'Files'. Cannot convert the 
"System.Tuple`2[System.String,System.String][]" value of type "System.Tuple`2[[System.String, mscorlib, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089]][]" to type "System.Tuple".
At line:1 char:26
+ Perform-Download -Files $files
+                          ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Perform-Download], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Perform-Download

What am I doing wrong?

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130

2 Answers2

2

Leveraging what What Would Be Cool wrote, I tried the following. Basically $Files is passed as an [array] then it's typecasted to a Tuple. I created a dummy Save-File which only writes the parameters to the output.

I'm not sure why the Tuple can't be passed as a parameter directly, you might have found a bug.

$files = @([System.Tuple]::Create("Flinstone","Rubble"), [System.Tuple]::Create("Simpsons","Flanders"))
function Save-File 
{
    Param ($URL, $DestinationFolder)
    Write-output ("{0} {1}" -f $URL, $DestinationFolder)    
}
Workflow Perform-Download
{
    Param (
    [Parameter(Mandatory = $true)]
    [array] $Files
    )

    $Files = [System.Tuple[string,string][]] $Files
    ForEach -Parallel ($file in $Files)
    {
        Parallel{Save-File -Url $file.Item1 -DestinationFolder $file.Item2}
    }
}

Perform-Download -Files $files
Micky Balladelli
  • 9,781
  • 2
  • 33
  • 31
0

This worked in a simple script:

param([System.Tuple[string,string][]]$files)

foreach ($file in $files) {
    [console]::WriteLine("Item1: {0}, Item2: {1}", $file.Item1, $file.Item2)
}

Then setting up the data and calling the script.

PS C:\data> $fileList = @([System.Tuple]::Create("Flinstone","Rubble"), [System.Tuple]::Create("Simpsons","Flanders"))

PS C:\data> .\soTuple.ps1 -files $fileList
Item1: Flinstone, Item2: Rubble
Item1: Simpsons, Item2: Flanders

See this article on using Tuples in PowerShell

What Would Be Cool
  • 6,204
  • 5
  • 45
  • 42
  • Hi, thanks for answering. I already know that if I use a function instead of a workflow the script works. I just don't understand why it doesn't work with a workflow – Maria Ines Parnisari Nov 24 '14 at 05:45