c# - 从C#调用get-aduser

标签 c# powershell

这是我上一个问题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/

相关文章:

c# - 简单的 C# Xml 序列化

c# - 如何强制不优化 ASP.NET Core 5 源代码

azure - PowerShell 列出所有 Azure VM 数据磁盘大小困惑

Powershell 自定义对象 toString 值用作 Note 属性

powershell - 如何使用powershell进行多线程复制?

c# - 如何在 C# 中构建 Web 服务缓存

c#代码效率

powershell - 用于创建 Azure 服务总线队列和主题的 Azure powershell cmdlet

.net - Powershell 和 HtmlAgilityPack

c# - 使用 MVVMLight 在 ViewModel 之间传递参数