Convert powershell cmdlet to C#

457 Views Asked by At

How could I convert the follow powershell command to C# code, especially parameters for -index.

Get-Mailbox | select-object -index 0, 1, 2, 3, 4, 5

I just want to retrieve the mail box many times to avoid extremely big memory usage.

How to set 0, 1, 2, 3, 4, 5 to CommandParameters?

1

There are 1 best solutions below

2
On

I'm not a programmer but this is should get you closer:

Command cmdMailbox = new Command("Get-Mailbox");
cmdMailbox.Parameters.Add("Identity", 'someone');

Command cmdSelect = new Command("Select-Object");
int[] indexes = new int[] {0,1,2,3,4,5}; 
cmdSelect.Parameters.Add("Index",indexes );