Getting different results using the pipeline with functions

Question:

I’m finding that passing objects to functions through the PowerShell pipeline converts them to string objects. If I pass the object as a parameter it keeps its type. To demonstrate:

I have the following PowerShell function which displays a object’s type and value:

I ran this script to test the function:

This produces the output:

EDIT: How can I use the pipeline to pass an entire array to a function?

Answer:

To process multiple items recieved via the pipeline you need a process block in your function:

More info:

Source:

Getting different results using the pipeline with functions by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply