How to get DatabaseCopies from MailboxDatabase programmatically in C# (wrapped ExchangeMangementShell cmdlets in c#)?

烂漫一生 提交于 2020-01-06 11:01:17

问题


I am wrapping ExchangeManagementShell Cmdlets in C#, to programmatically execute cmdlets (Please refer to __http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/155504b3-ffe3-4bdf-887a-1e61842a8697)

I know the "databasecopies" property of mailboxdatabase contains copies. But i am not sure how to parse the deserilzied databasecopies data to get the properites.

Please see the below code snippet. I am basically parsing Get-MailboxDatabase cmdlet results to get the properties we are interested in. Not sure, how to get the DatabaseCopies from it though.

foreach (PSObject cmdletResults in this.Execute("Get-MailboxDatabase"))
{
   MailboxDatabase mdb = new MailboxDatabase();
   mdb.ExchangeApplicationSystemGlobalId = this.ExchangeApplicationSystem.GlobalId;
   mdb.Name = cmdletResults.Properties["Name"].Value.ToString();
   mdb.MountedOnServer = cmdletResults.Properties["Server"].Value.ConvertToString();
   mdb.EdbFilePath = cmdletResults.Properties["EdbFilePath"].Value.ConvertToString();
   mdb.LogFolderPath = cmdletResults.Properties["LogFolderPath"].Value.ConvertToString();
   mdb.LogFilePrefix = cmdletResults.Properties["LogFilePrefix"].Value.ConvertToString();
   mdb.Guid = cmdletResults.Properties["Guid"].Value.ToString();
   string mt = cmdletResults.Properties["MasterType"].Value.ConvertToString();
   if (!string.IsNullOrEmpty(mt))
   {
      mdb.MasterType = mt.ToEnum(MasterType.Unknown);
   }
   mdb.MasterServerOrAvailabilityGroup = cmdletResults.Properties["MasterServerOrAvailabilityGroup"].Value.ConvertToString();
   PSObject pso = cmdletResults.Properties["Servers"].Value as PSObject;
   if (null != pso
          && null != pso.BaseObject)
   {
       ArrayList servers = pso.BaseObject as ArrayList;
       if (null != servers)
       {
           mdb.Servers = servers.ToArray().Where(server => null != server)
                                .Select(server => server.ToString())
                                .ToArray();
       }
    }
}                    

回答1:


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] d oesn't contain a method named 'gettype'. At line:1 char:12 + $md.gettype <<<< () + CategoryInfo : InvalidOperation: (gettype:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound

So, looks like i dont have any choice. I will looking for work around for my use case.

regards, Dreamer



来源:https://stackoverflow.com/questions/14643469/how-to-get-databasecopies-from-mailboxdatabase-programmatically-in-c-sharp-wrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!