Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop PowerShell from unpacking an Enumerable object?

Tags:

powershell

Working on a simple helper function in PowerShell that takes a couple of parameters and creates a custom Enumerable object and outputs that object to the pipeline. The problem I am having is that PowerShell is always outputting a System.Array that contains the objects that are enumerated by my custom Enumerable object. How can I keep PowerShell from unpacking the Enumerable object?

The code: http://gist.github.com/387768

like image 420
Eric Schoonover Avatar asked May 03 '10 04:05

Eric Schoonover


People also ask

What is @() in PowerShell?

What is @() in PowerShell Script? In PowerShell, the array subexpression operator “@()” is used to create an array. To do that, the array sub-expression operator takes the statements within the parentheses and produces the array of objects depending upon the statements specified in it.

How do you clear an array in PowerShell?

delete element It's not easy to delete array element in PowerShell. Array data structure is not designed to change size. Instead of delete, just replace the value with $null .

How do I add an object to an array in PowerShell?

Use += to Add Objects to an Array of Objects in PowerShell The Plus Equals += is used to add items to an array. Every time you use it, it duplicates and creates a new array. You can use the += to add objects to an array of objects in PowerShell.


1 Answers

Try to change the line 46 from

$row

to

, $row

EDIT: as Johannes correctly pointed out, the unary operator comma creates an array with one member.

like image 159
Roman Kuzmin Avatar answered Jan 21 '23 09:01

Roman Kuzmin