Powershell – an empty pipe element is not allowed

Question:

I keep receiving the following error message – “An empty pipe element is not allowed” whenever I try to pipe out my results to a csv file. Any idea why this might be happening?

I’ve tried doing this:

within the foreach loop but it only returns the last record.

Answer:

I believe the problem you are having is around the use of foreach and the the pipeline, you are processing your items in the foreach statement but still expecting them to be on the pipeline.

This is a common error and is explained in more detail in the article Essential PowerShell: Understanding foreach and Essential PowerShell: Understanding foreach (Addendum).

You should be able to achieve what you want like this:

Source:

Powershell – an empty pipe element is not allowed by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply