.net - Exchange Management Powershell-如何在这里获取Name属性的值?

标签 .net powershell

如何获取仅名称变量的返回值?

RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
PSSnapInInfo info = rsConfig.AddPSSnapIn(“Microsoft.Exchange.Management.PowerShell.Admin”,snapInException外);
运行空间myRunSpace = RunspaceFactory.CreateRunspace(rsConfig); myRunSpace.Open();

//创建管道并向其提供脚本文本
管道管道= myRunSpace.CreatePipeline();

字符串strScript =“Get-MailboxDatabase”;

//将命令添加到管道的Commands集合中。
pipeline.Commands.AddScript(strScript)

收集结果= pipe.Invoke();

最佳答案

有几种不同的方法可以做到这一点。更改脚本:

string strScript = "Get-MailboxDatabase | select -expand name"

这样,results[0].BaseObject将是一个纯字符串。或者,您可以从PSObject检索包含邮箱数据库实例的Name属性:
string name = results[0].Properties["Name"].Value

或者您可以通过将results[0].BaseObject强制转换为该Type并以强类型方式访问该属性,从而从邮箱数据库Type中获取它(对不起,我不知道它到底是什么)。

-Oisin

关于.net - Exchange Management Powershell-如何在这里获取Name属性的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3290366/

相关文章:

.net - 用户在采用 Silverlight 时是否有问题?

c# - 类中通用项目的通用集合?

Powershell 导入 Azure 发布设置无效的 XML

powershell - 使用 powershell 命令获取磁盘使用情况

Powershell - 根据文件名将文件复制到不同的目标文件夹

.net - Winforms - 单击/拖动表单中的任意位置以移动它,就像在表单标题中单击一样

c# - .NET Linq 左连接

c# - 如何在非托管内存中实例化 C# 类? (可能的?)

powershell - 在 PowerShell 中将二维数组输出到 csv 文件

powershell - PowerShell Access.Application Transfertext 将数字列导出到 CSV 文件时保持小数精度