Powershell function returning an array instead of string

Question:

i’m importing a csv and i would like to add a column to it (with the result based off of the previous columns)

my data looks like this

i would like to add a column called “sub site”

so I wrote this module but the problem is, the actual ending object is an array instead of string

if I run the command

when it should look like

EDIT: I found the solution but the question is now WHY.

If I change my function to $s -match "\d\d\d" |out-null I get back the expected 400

Answer:

Good you found the answer. I was typing this up as you found it. The reason is because the -match returns a value and it is added to the pipeline, which is all “returned” from the function.

For example, run this one line and see what is does:

It prints True.

Since I had this typed up, here is another way to phrase your question with the fix…

Source:

Powershell function returning an array instead of string by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply