This is a continuation of my previous question Invoking powershell cmdlets from C#
I want to invoke the active directory cmdlet get-aduser from within C#, and the first parameter it takes is a filter. The full cmdlet I'm trying to execute is:
get-aduser -filter {name -eq "joe bloggs"} -Properties * | select employeeID
Following from my previous question (See link above), I created a scriptblock to do that:
ps2.Commands.AddCommand("get-aduser");
string script = string.Format("name -eq \"{0}\"", fullname); //fullname constuction now shown
ScriptBlock filter2 = ScriptBlock.Create(script);
ps2.AddParameter("FilterScript", filter2);
ps2.AddParameter("Properties").AddArgument("*");
ps2.AddCommand("select").AddArgument("employeeID");
ps2.Invoke();
However, when I execute this, I get an exception at ps2.Invoke():
A parameter cannot be found that matches parameter name 'FilterScript'.
Any suggestions on this one?
Thanks in advance