[英]How to get the properties of Cmdlet results which contain list of deserialized objects (multi-valued properties)(executing powershell cmdlets from c#)
I am using c# to execute PowerShell cmdlets and parsing the cmdlet results (Collection[].Properties["PropertyName"].value) to get the required values. 我正在使用c#执行PowerShell cmdlet并分析cmdlet结果(Collection []。Properties [“ PropertyName”]。value)以获取所需的值。
But some of the results contains a list of deserialized objects. 但是其中一些结果包含反序列化对象的列表。 But PowerShell is simply converting these to ArrayList of objects and i am unable to get all the properties of them.
但是PowerShell只是将它们转换为对象的ArrayList,而我无法获取它们的所有属性。
For ex: Get-MailboxDatabase of Exchange Management Shell cmdlet returns list of mailboxdatabase on exchange server (Collection). 例如:Exchange命令行管理程序cmdlet的Get-MailboxDatabase返回Exchange服务器(集合)上的邮箱数据库列表。 I can able to get properties like name, server etc... from PSObject.Properties["PropertyName"].Value.
我可以从PSObject.Properties [“ PropertyName”]。Value获取属性,例如名称,服务器等。
It also contains a list of database copies (something like below) 它还包含数据库副本的列表(如下所示)
class MailboxDatabase { DatabaseCopy[] DatabaseCopies; 类MailboxDatabase {DatabaseCopy [] DatabaseCopies; }
}
the PSObject.Properties["DatabaseCopies"].Value is nothing but an arrayList of objects. PSObject.Properties [“ DatabaseCopies”]。Value只是对象的arrayList。
But all the DatabaseCopy properties are not deserialized (Or- i am not sure how to get them). 但是所有的DatabaseCopy属性都不会反序列化(或者-我不确定如何获取它们)。
I can only seee the Name (tostring of DatabaseCopy from the list of arraylists). 我只能看到名称(从arraylists列表中的DatabaseCopy的字符串)。
Can any one please help me how to get all the deserialized properties of multi-valued results? 谁能帮助我如何获得多值结果的所有反序列化属性?
For more details you can look at: How to get DatabaseCopies from MailboxDatabase programmatically in C# (wrapped ExchangeMangementShell cmdlets in c#)? 有关更多详细信息,请查看: 如何在C#中以编程方式从MailboxDatabase获取数据库副本(在C#中包装ExchangeMangementShell cmdlet)?
Regards, Dreamer 问候,梦想家
Even from PowerShell, they are coming as plain strings. 即使从PowerShell,它们也以纯字符串形式出现。
PS C:\> $md.type
PS C:\> $md.DatabaseCopies.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ArrayList System.Object
PS C:\> $md.DatabaseCopies[0].gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS C:\> $md.gettype()
Method invocation failed because [Deserialized.Microsoft.Exchange.Data.Directory.SystemConfiguration.MailboxDatabase] doesn't contain a method named 'gettype'.
So, looks like I don't have any choice. 所以,看来我别无选择。 I will looking for work around for my use case.
我将为我的用例寻找解决方法。
The cmdlets should return the PSObject or a list of PSObject. cmdlet应该返回PSObject或PSObject列表。
I think the DatabaseCopies is not serialized and just set to plain string. 我认为DatabaseCopies没有序列化,只是设置为纯字符串。 So they cannot be deserialized.
因此它们不能反序列化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.