PowerShell ParameterBindingException
I found that each command must be invoked separately, since they are not related. The question arose from my misunderstanding of the concept of Powershell pipelines.
Why are you declaring command as var
? I mean:
Command NewAddressList = new Command("New-AddressList");
Then, try adding commands as CommandParameter
objects (as suggested here):
CommandParameter NameParam = new CommandParameter("Name","7 AL");NewAddressList.Parameters.Add(NameParam);
Finally, why are you not using the Powershell
class directly?
EDIT: Further guess after tracing
The overloaded version of Parameters.Add
you are using takes as arguments a key (string) and a value (object). Probably c# does not do the same good job powershell does :/. Try passing values as objects of the required type. For example, the included-recipient
parameter wants a Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType
.
Try casts.
Example:
Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType allrecips = (Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType) "AllRecipients";NewAddressList.Parameters.Add("IncludedRecipients", allrecips);
or (I know it may be silly):
NewAddressList.Parameters.Add("IncludedRecipients", "[Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType] AllRecipients");