//////////////////////////////////////////////////////////////////////////////// // Proof that the bug in Select-Object didn't need to be there. You can detect whether // the input is passed in on the pipeline or as a paramenter. If it's from the pipeline, then it // will NOT be present at BeginProcess() but if you pass it in as an argument, then it will. // // Try it out: "a","b","c"| Test-Pipeline -verbose // Versus this: Test-Pipeline -verbose -input @("a","b","c") //////////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using System.Management.Automation; using System.Collections; namespace Huddled.TestSnapin { [Cmdlet(VerbsDiagnostic.Test, "Pipeline")] public class TestPipelineCommand : Cmdlet { #region Parameters [Parameter(Position = 0, Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Help Text"), ValidateNotNullOrEmpty] public string Name { get { return _name; } set { _name = value; } } private string _name = "TestPipeline"; [Parameter(Position = 1, Mandatory = false, ValueFromPipeline = true, HelpMessage = "Help Text"), ValidateNotNullOrEmpty] public string[] InputObject { get { return _input; } set { _input = value; } } private string[] _input; #endregion protected override void BeginProcessing() { WriteVerbose(String.Format("Begin Processing {0}", Name)); if (_input != null && _input.Length > 0) { throw new ArgumentException("You cannot pass data to via the InputObject parameter, you must pass it via the pipeline.", "InputObject"); } base.BeginProcessing(); } protected override void ProcessRecord() { if (_input != null && _input.Length > 0) { foreach (string input in _input) { WriteVerbose(String.Format("Process: {0}", input)); WriteObject(input); } } } protected override void EndProcessing() { WriteVerbose(String.Format("End Processing {0}", Name)); base.EndProcessing(); } } }