Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:17:41+00:00 2026-06-17T05:17:41+00:00

How to consume data from pipeline when writing cmdlets in C#? For example I

  • 0

How to consume data from pipeline when writing cmdlets in C#?

For example I have two classes:

This one produces data:

[Cmdlet(VerbsCommon.Get, "Numbers")]
public class GetNumbers : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject(new[] {1, 2, 3, 4, 5}, true);
    }
}

And this one must consume this data:

[Cmdlet(VerbsCommon.Find, "Numbers")]
public class FindNumbers: Cmdlet
{
    protected override void ProcessRecord()
    {
        foreach (var variable in %Input%) // Where do I get input? Any ReadRecord or something else?
        {
            if (variable % 2 == 0)
            {
                WriteObject(variable);
            }
        }
    }
}

In this way:

Get-Numbers | Find-Numbers
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:17:42+00:00Added an answer on June 17, 2026 at 5:17 am

    You should use ValueFromPipeline of ParameterAttribute class:

    [Cmdlet(VerbsCommon.Find, "Numbers")]
    public class FindNumbers: Cmdlet
    {
        [Parameter(ValueFromPipeline = true)] // The data appear in this variable
        public int[] Input { get; set; }
    
        protected override void ProcessRecord()
        {
            foreach (var variable in Input)
            {
                if (variable % 2 == 0)
                {
                    WriteObject(variable);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: old legacy code in rpg have to consume data from a new web
I have to consume data from axis2 webservice. I added it's URI to Service
This one is doing my head in... I need to retrieve data from Oracle
I am trying to consume data from a webservice published by a 3rd party.
I'm writing a bunch of data out from a java application that gets consumed
I have a Compact Framework 2.0 app that consume a WCF service. The data
I consume Java Service in my .NET appliaction. I have one question: When service
I have a bytearray consisting of data received from a WebSocket-client. The data I
I have been asked to develop a system that collects data from a Sql
I want to consume an IntentService for my app to laod data from server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.