C# 从C中的powershell脚本获取集合#
试图在C#应用程序中获取项目集合作为PowerShell脚本的输出,但它始终返回空集合 结果。计数:程序执行后为0 (当然,Exchange筛选器列表不是空的) 有人能解释一下我做错了什么吗 以下是我的部分代码:C# 从C中的powershell脚本获取集合#,c#,powershell,C#,Powershell,试图在C#应用程序中获取项目集合作为PowerShell脚本的输出,但它始终返回空集合 结果。计数:程序执行后为0 (当然,Exchange筛选器列表不是空的) 有人能解释一下我做错了什么吗 以下是我的部分代码: var rsConfig = RunspaceConfiguration.Create(); using (var myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)) {
var rsConfig = RunspaceConfiguration.Create();
using (var myRunSpace = RunspaceFactory.CreateRunspace(rsConfig))
{
var info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out PSSnapInException snapInException);
myRunSpace.Open();
using (var ps = PowerShell.Create())
{
//Getting existing list of blocking rules
ps.AddScript("Get-ContentFilterPhrase | Where-Object {$_.Influence -Match 'BadWord'}| Format-Table -Property Phrase");
var results = ps.Invoke(); //Run PS script
//Debug!
MessageBox.Show("Script executed!", "Script executed!", MessageBoxButtons.OK, MessageBoxIcon.Information);
listBox1.Items.Add(results);
Console.WriteLine("results.Count: {0}", results.Count);
// Is there something in results?
if (results.Any())
{// Looking at every object in collection
foreach (var result in results)
{
//Debug!
listBox1.Items.Add("Object");
//Looking at every property of every object in collection
foreach (PSPropertyInfo propertyInfo in result.Properties)
{
//Debug!
listBox1.Items.Add("Property");
//Writing propertyes to Console
Console.WriteLine(string.Format("{0}: {1}", propertyInfo.Name, propertyInfo.Value));
continue;
}
continue;
}
} else listBox1.Items.Add("Results're empty!");
Format Table
永远不会返回您要查找的项目集合。这是一个格式化cmdlet,旨在用于输出格式化。Format Table
的可能重复项永远不会返回您正在查找的项目集合。这是一个格式化cmdlet,旨在用于输出格式化。的可能重复