Search Wiki:

OverrideProcessRecordIfAcceptingPipelineInput


TypeName OverrideProcessRecordIfAcceptingPipelineInput
CheckId PS1001
Error-Level Error
Category Microsoft.PowerShell
Certainty 95%
BreakingChangeNon-breaking
Cause The cmdlet has a parameter that takes input from the pipeline, but the cmdlet does not override the ProcessRecord input processing method, as is required.
Rule descriptionDuring execution of the BeginProcessing and EndProcessing methods, pipeline input is not correctly bound to a cmdlet parameter. A cmdlet must override a ProcessRecord method to handle pipeline input bound to parameters correctly.
|How to fix violations| Do one of the following: 1) Override a ProcessRecord method, and use this method to handle pipeline input bound to parameters, -or-
2) Do not use the ValueFromPipeline or ValueFromPipelineByPropertyName properties of the ParameterAttribute attribute, which bind the parameter to pipeline input. |
When to exclude warnings Do not suppress warnings from this rule.
Related rules DoNotAccessPipelineParametersOutsideProcessRecord
See also FxCop Rules for Windows PowerShell

Examples

[Cmdlet("Write", "String")]
    public class WriteStringCommand : PSCmdlet
    {
        [Parameter(ValueFromPipeline = true)]
        public string[] InputObject
        {
            get { return this.inputObject; }
            set { this.inputObject = value; }
        }
        private string[] inputObject;
 
        // The following command does not work correctly:
        //   "aaa", "bbb", "ccc" | Write-String
        // 
        // To fix the error in the example, 
        // change the BeginProcessing method 
        // to ProcessRecord.
        protected override void BeginProcessing()
        {
            // this.inputObject should be accessed
            // only within a ProcessRecord method.
            foreach (string s in this.inputObject)
            {
                this.Host.UI.WriteLine(s);
            }
        }
    }

Back to FxCop Rules for Windows PowerShell.
Last edited Mar 26 2010 at 4:19 PM  by JuneB, version 2
Updating...
Page view tracker