I'm getting a, possibly misleading, error when i try to execute powershell from my c# app using powershell.
The error, as in the title, suggests that i'm missing the Identity parameter, but it isn't missing. I tried debugging through, and confirming that the parameter is added to the Command object, before invoking.
var x = ps.AddScript("Remove-CsOnlineVoiceRoutingPolicy")
.AddParameter("Identity", "DK")
.AddParameter("-Force");
x.Invoke();
I'm running powershell 7.2, and using System.Management.Automation.Powershell version 7.2.1.0
Any ideas as to why this happens ?
I've tried both parameters with and without the dash, making no difference.
CodePudding user response:
The error was using AddScript in addition with addParameter. When using add scripts the params should be inline in the script, if you want to use addPArameter, it should be following the AddCommand.
dashes in the parameter name in AddParameter() seems to be completely ignored.
a working example would look like this.
var x = ps.AddCommand"Remove-CsOnlineVoiceRoutingPolicy")
.AddParameter("Identity", "DK")
.AddParameter("Force");
x.Invoke();