I want to write a cmdlet that reads multiple records from a database and puts them onto the pipeline.
I think I can do either a single WriteObject(Enumerable<rec>, true) or I can loop myself and call WriteObject multiple times.
What’s the difference between these two?
Here is the documentation: Cmdlet.WriteObject Method (Object, Boolean)
And here is the example:
Output:
Thus, calling
WriteObject(item)for each item in a collection is basically the same asWriteObject(items, true); in both cases the collection itself has gone.WriteObject(items, false)is different; it returns a reference to the collection and the caller can use that effectively depending on a scenario. For example, if a collection is aDataTableobject (not unrolled set ofDataRowitems) then a caller can operate onDataTablemembers of the returned object.