title: How do I fix the problem I have with passing all objects output via the pipeline?
body: <p>I am writing a PowerShell module to make use of the API for a Storage System in C# and I have come across a problem I cannot get my head around. I have one command that can pipe one or more objects in to another and ProcessRecord() process them all individually as you would expect. However, this is only when I name the items in the first cmdlet, or save it as a variable in PowerShell first.</p>
  
  <p>Here is what I see in PowerShell when I do this:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS C:\&gt; $a = Show-ISSFileSystem -Name fs1
  PS C:\&gt; $b = Show-ISSFileSystem -Name fs1,cesSharedRoot
  PS C:\&gt; $c = Show-ISSFileSystem    # Contains the two objects listed above.
  
  # Types
  PS C:\&gt; $a.Gettype().Fullname
  ISS.FileSystemInfo.Filesystem
  PS C:\&gt; $b.Gettype().Fullname
  System.Object[]
  PS C:\&gt; $c.Gettype().Fullname
  ISS.FileSystemInfo.Filesystem[]
  
  # Introduce second command
  PS C:\&gt; $a | Show-ISSFileset                    # Returns as expected
  PS C:\&gt; $b | Show-ISSFileset                    # Returns as expected
  PS C:\&gt; $c | Show-ISSFileset                    # Returns as expected
  PS C:\&gt; Show-ISSFileSystem | Show-ISSFileSet    # Fails, complaining about the input object - Custom Class(Filesystem)
  
  Show-ISSFileset : The input object cannot be bound to any parameters for the command either because the command does
  not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
  
  # Counting objects
  PS C:\&gt; (Show-ISSFileSystem -Name fs1 | Measure-Object).Count               # Returns 1 as expected
  PS C:\&gt; (Show-ISSFileSystem -Name fs1,cesSharedRoot | Measure-Object).Count # Returns 2 as expected
  PS C:\&gt; (Show-ISSFileSystem | Measure-Object).Count                         # Returns 1, even though the variable has two objects
  PS C:\&gt; ($c | Measure-Object).Count                                         # Saved to variable first, the command above correctly returns 2 as expected.
  </code></pre>
  
  <p>I can add parts of code if necessary, but I just wanted to know if anyone had any quick thoughts about what might be happening here. It can quite clearly deal with multiple objects, but not directly from the first function unless we name one (I have used ValueFromPipeline and not ValueFromPipelineByProperty). There is a lot of code and I was struggling to provide a minimal example.</p>
  
  <p>It is like the first command is mashing the objects together when run directly and the second one doesn't know what the input is. Anyone had a similar problem?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Okay, so I realised that it is something strange going on with the output. After I converted the response from JSON, if the Name parameter was specified, I was running it through .Where() and the end result was a List of objects. Anything going through that was coming out and through the pipeline okay. If Name wasn't specified, it was writing the converted Json object directly.</p>
  
  <p>Didn't work:</p>
  
  <pre class="lang-cs prettyprint-override"><code>// Convert from Json
  FileSystemInfo _convertJson = FileSystemInfo.FromJson(_response);
  
  // Filter by name if requested
  if (Name != null)
  {
      List&lt;Filesystem&gt; FileSystems = _convertJson.Filesystems.Where(
          f =&gt;
              Regex.IsMatch(f.Name.ToString(),
                  string.Format("(?:{0})", string.Join("|", Name)))).ToList();
      FileSystems.ForEach(WriteObject);
  }
  else
  {
      WriteObject(_convertJson.Filesystems);
  }
  </code></pre>
  
  <p>Works:</p>
  
  <pre class="lang-cs prettyprint-override"><code>// Convert from Json
  FileSystemInfo _convertJson = FileSystemInfo.FromJson(_response);
  
  // Filter by name if requested
  if (Name != null)
  {
      List&lt;Filesystem&gt; FileSystems = _convertJson.Filesystems.Where(
          f =&gt;
              Regex.IsMatch(f.Name.ToString(),
                  string.Format("(?:{0})", string.Join("|", Name)))).ToList();
      FileSystems.ForEach(WriteObject);
  }
  else
  {
      _convertJson.Filesystems.ToList().ForEach(WriteObject);
  }
  </code></pre>
  
  <p>Perhaps this isn't the best answer and someone can correct me. I have only been learning C# three months.</p>
  
  <p><strong>UPDATE2:</strong></p>
  
  <p>Many thanks to PetAlSer and Mathias below for pointing me in the right direction. The list conversion above was not necessary, only needed to enumerate the collection as part of WriteObject so that the second cmdlet would receive each object.</p>
  
  <pre class="lang-cs prettyprint-override"><code>WriteObject(_convertJson.Filesystems, true);
  </code></pre>