I run a PowerShell from within a C# form application. I want to add multiple parameters to my PowerShell command.
But when I enter a second AddParameter call, it failed with the error:
System.Management.Automation.ParameterBindingException
Code:
PowerShell shell = PowerShell.Create().AddCommand("Get-NetAdapter");
shell.AddParameter("name", "Ethernet*");
shell.AddParameter("InterfaceIndex", "5");
foreach (PSObject result in shell.Invoke())
{
Console.WriteLine("{0,-24}{1}", result.Members["Name"].Value,
result.Members["InterfaceDescription"].Value);
} // End foreach.
It looks like it only accepts 1 parameter.
There is also a AddParameters, but I'm not able to get this working.
Anyone got any experience with this?