首页 > 解决方案 > C# 获取要转换为 PSObject 的数组

问题描述

我正在尝试使用 System.Management.Automation 命名空间来使用 c# 中来自 PowerShell 的内置 gridviewer,但是我似乎无法让它显示我的项目列表,它总是将其返回为一行就像我试图获取数组的信息而不是它的成员一样。

SomeClass[] list; //let's say I have a simple array of one object type
PowerShell posh = PowerShell.Create();
posh.AddCommand("Out-Gridview");
posh.AddArgument(list); //this inputs the list as first argument for the command
posh.Invoke(); //this now just opens a gridview with information about the list itself (length, syncroot, ...)

所以我想要一种将我已经存在的列表转换为我的 C# 代码中的 powershell 兼容对象的方法,最好只使用自动化库和其他默认的 .NET 类。

标签: c#powershell

解决方案


推荐阅读