这是我上一个问题Invoking powershell cmdlets from C#的继续
我想从C#中调用 Activity 目录cmdlet get-aduser,它采用的第一个参数是过滤器。我要执行的完整cmdlet是:
get-aduser -filter {name -eq "joe bloggs"} -Properties * | select employeeID
在上一个问题之后(请参见上面的链接),我创建了一个脚本块来做到这一点:
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();
但是,执行此操作时,在ps2.Invoke()处出现异常:
A parameter cannot be found that matches parameter name 'FilterScript'.
关于这个有什么建议吗?
提前致谢
最佳答案
Get-ADUser没有'FilterScript'参数(Where-Object有),请使用'Filter':)
关于c# - 从C#调用get-aduser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17091035/