title: Stop cmdlet after X iterations
body: <p>I have a cmdlet that takes pipeline values:</p>
  <pre><code>1..10 | Test-MyCmdlet
  </code></pre>
  <p>I want to limit <code>Test-MyCmdLet</code> to only process the first 5 objects (<em>edit</em> not by limiting the input piped to it.)</p>
  <p>My first solution was to set a counter in the <code>BEGIN</code> block, increment that in the <code>PROCESS</code> block, and break out of the process block once it reaches a threshold. That seems a little 'hacky' to me.</p>
  <p>Is there a better way?</p>
  <p>The tl;dr version of how I arrived at this question is:</p>
  <p>I have a C# module that defines a cmdlet <code>Open-View</code> with the following parameter</p>
  <pre><code>[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
  public IViewDef[] View {get; set;}
  </code></pre>
  <p>where <code>IViewDef</code> is a custom type from another assembly. The cmdlet opens windows in a 3rd party app.</p>
  <p><code>IViewDef</code> has a property called <code>Name</code></p>
  <p>I wanted to make the cmdlet a little more versatile so I changed it to this:</p>
  <pre><code>[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByParameterName = true)] // by parameter name
  public string[] Name {get; set;} // notice that this is now Name
  </code></pre>
  <p>Now I can also call it from the CLI and type my own viewnames.</p>
  <p>This introduces a problem tho: it no longer recognizes <code>IViewDef</code> objects piped in. I think that is because <code>ValueFromPipelineByParameterName</code> expects the parameter name of the input object to be of the same signature, ergo <code>string[]</code>.</p>
  <p>So I changed it to:</p>
  <pre><code>[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByParameterName = true)]
  public string Name {get; set;} // no more array
  </code></pre>
  <p>That works, <em>but</em> there is a reason I originally defined it as an array: I wanted to be able to count the number of views being passed in and stop processing them if their number reaches a threshold. I can now no longer do that. Back to the original question.</p>