C# PowerShell在C中获取ChildItem调用#

C# PowerShell在C中获取ChildItem调用#,c#,powershell,c#-4.0,C#,Powershell,C# 4.0,我将下面的powershell脚本转换为C# 我试过这个,但没有成功 string dllName = "MyOwn.dll"; PowerShell ps = PowerShell.Create(); ps.AddCommand("Get-ChildItem"); ps.AddParameter(@"C:\Windows\Microsoft.NET\assembly"); ScriptBlock filter =

我将下面的powershell脚本转换为C#

我试过这个,但没有成功

        string dllName = "MyOwn.dll";
        PowerShell ps = PowerShell.Create();
        ps.AddCommand("Get-ChildItem");
        ps.AddParameter(@"C:\Windows\Microsoft.NET\assembly");
        ScriptBlock filter = ScriptBlock.Create(dllName);
        ps.AddParameter("-Filter", filter);
        foreach (PSObject result in ps.Invoke())
        {
            Console.WriteLine(
                "{0,-24}{1}",
                result.Members["Length"].Value,
                result.Members["Name"].Value);
        } 
在C#中是否有与Get ChildItem等价的东西

请帮忙


谢谢。

我知道这是一个相当老的问题,但由于它没有答案,而且与我刚才回答的问题有关,我想我也可以解决这个问题。我发现执行“Get ChildItem”的工作方式是,而不是使用
PowerShell。Create()
使用
RunspaceInvoke
并按原样抛出命令。以下是本案例的工作原理:

using (RunspaceInvoke invoke = new RunspaceInvoke())
{
       Collection<PSObject> result = invoke.Invoke("Get-ChildItem \"C:\\Windows\\Microsoft.NET\\assembly\" -Filter \"Microsoft.GroupPolicy.Management.Interop.dll\" -Recurse | Select-Object -ExpandProperty VersionInfo");
}
使用(RunspaceInvoke=new RunspaceInvoke())
{
收集结果=invoke.invoke(“Get ChildItem\”C:\\Windows\\Microsoft.NET\\assembly\'-Filter\'Microsoft.GroupPolicy.Management.Interop.dll\'-Recurse | Select Object-ExpandProperty VersionInfo”);
}
using (RunspaceInvoke invoke = new RunspaceInvoke())
{
       Collection<PSObject> result = invoke.Invoke("Get-ChildItem \"C:\\Windows\\Microsoft.NET\\assembly\" -Filter \"Microsoft.GroupPolicy.Management.Interop.dll\" -Recurse | Select-Object -ExpandProperty VersionInfo");
}