0

I have a C# script to mail-enable a distribution group in Exchange. I have tried the following code, which works currently:

Command command = new Command("Enable-DistributionGroup -Identity '#Test DL'");
psInstance.Commands.AddCommand(command);

The above code works, and will return a string with the name of the distribution group. Upon checking the distribution group, it has become mail-enabled.

The below code does not work, and returns an empty string:

Command command = new Command("Enable-DistributionGroup").AddParameter("Identity", "#Test DL");
psInstance.Commands.AddCommand(command);

Am I using the AddParameter function incorrectly?

1 Answer 1

2

You need to create the command object, and then do a command.AddParameter separately. See the C# example at PowerShell.AddParameter Method

You can also reference Usage of powerShell.AddCommand for an example from another SO poster.

Sign up to request clarification or add additional context in comments.

1 Comment

I have also tried the following but to no avail: Command command = new Command("Enable-DistributionGroup"); command.addParameter("Identity", "#Test DL"); psInstance.Commands.AddCommand(command);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.