开发者

Exchange Management Powershell - How can I get the value of the Name property here?

开发者 https://www.devze.com 2023-01-07 21:11 出处:网络
How can I get the return value of only the Name Variable? RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();

How can I get the return value of only the Name Variable?

RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", o开发者_StackOverflow中文版ut snapInException); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig); myRunSpace.Open();

//Create pipeline and feed it the script text Pipeline pipeline = myRunSpace.CreatePipeline();

string strScript = "Get-MailboxDatabase";

//Add the command to the Commands collection of the pipeline. pipeline.Commands.AddScript(strScript)

Collection results = pipeline.Invoke();


There are a few different ways to do this. Alter your script:

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

with this, results[0].BaseObject will be a plain string. Or you can retrieve the Name property from the PSObject wrapping the mailbox database instance:

string name = results[0].Properties["Name"].Value

or you can grab it from the mailboxdatabase Type (sorry, I don't know what that actually is) by casting results[0].BaseObject to this Type and accessing the property in a strongly-typed fashion.

-Oisin

0

精彩评论

暂无评论...
验证码 换一张
取 消