Question

I need to write a custom powershell cmdlet in C# that would accept data and be able to enumerate over it. I have followed some examples online and have some working code.

The problem I have can be demonstrated as follows:

  1. I want a custom powershell cmdlet to take that output of another command as input to a parameter, so for example Get-Process
  2. I want my custom cmdlet to accept data in table format
  3. Enumerate over the data

The problem I have is that I am not sure how to setup a parameter to take a table of data in Not sure how to output data from my cmdlet in table form.

Can anyone provide any examples?

Was it helpful?

Solution

I have no idea what you mean with "table format". In PowerShell you should work with objects (or, of course, lists of objects).

What you want to do, to create a cmdlet which takes the output of one command as it's input, i.e. accepts pipeline input, is to mark one of your parameter to take the value from the pipeline. You can find good instructions on how to do this at the MSDN section on Adding Parameters that Process Pipeline Input.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top