How can I pass an array from C# to PowerShell that can be foreached?
Right now I have this script:
[Cmdlet(VerbsCommon.Get, "Numbers")]
public class GetNumbersCmdlet: Cmdlet
{
protected override void BeginProcessing()
{
var list = new List<string>();
list.Add("1");
list.Add("2");
list.Add("3");
list.Add("4");
list.Add("5");
WriteObject(results.ToArray());
}
}
And this PowerShell script:
foreach ($number in Get-Numbers) {
Write-Output "Output is $number"
}
Instead of:
Output is 1
Output is 2
Output is 3
Output is 4
Output is 5
I would get:
Output is 1 2 3 4 5
Get-Numbersand assign the results to a variable first thenforeachthat variable, everything works as intended. I've filed a bug report here.WriteObject(results.ToArray(), true);