0

I am using c# to execute PowerShell cmdlets and parsing the cmdlet results (Collection[].Properties["PropertyName"].value) to get the required values.

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.

For ex: Get-MailboxDatabase of Exchange Management Shell cmdlet returns list of mailboxdatabase on exchange server (Collection). I can able to get properties like name, server etc... from PSObject.Properties["PropertyName"].Value.

It also contains a list of database copies (something like below)

class MailboxDatabase { DatabaseCopy[] DatabaseCopies; }

the PSObject.Properties["DatabaseCopies"].Value is nothing but an arrayList of objects.

But all the DatabaseCopy properties are not deserialized (Or- i am not sure how to get them).

I can only seee the Name (tostring of DatabaseCopy from the list of arraylists).

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#)?

Regards, Dreamer

Community
  • 1
  • 1
Dreamer
  • 3,371
  • 2
  • 34
  • 50

2 Answers2

0

Even from PowerShell, they are coming as plain strings.

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.

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Dreamer
  • 3,371
  • 2
  • 34
  • 50
0

The cmdlets should return the PSObject or a list of PSObject.

I think the DatabaseCopies is not serialized and just set to plain string. So they cannot be deserialized.

terry
  • 1,569
  • 11
  • 19
  • But DatabaseCopy is a serializable class. for ex: its defined as [Serializable] public class DatabaseCopy : ADConfigurationObject, IActivationPreferenceSettable, IComparable { // Properties public int ActivationPreference { get; internal set; } internal int ActivationPreferenceInternal { get; set; } public string DatabaseName { get; } public string HostServerName { get; } public EnhancedTimeSpan ReplayLagTime { get; set; } [Parameter(Mandatory=false)] public EnhancedTimeSpan TruncationLagTime { get; set; } } – Dreamer Feb 06 '13 at 03:52