0

我在 C# 中包装 ExchangeManagementShell Cmdlet,以编程方式执行 cmdlet(请参阅 __http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/155504b3-ffe3-4bdf-887a-1e61842a8697)

我知道邮箱数据库的“数据库副本”属性包含副本。但我不确定如何解析 deserilzied databasecopies 数据以获取属性。

请看下面的代码片段。我基本上是在解析 Get-MailboxDatabase cmdlet 结果以获取我们感兴趣的属性。不知道如何从中获取 DatabaseCopies。

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();
       }
    }
}                    
4

1 回答 1

0

即使来自 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() 方法调用失败,因为 [Deserialized.Microsoft.Exchange.Data.Directory.SystemConfiguration.MailboxDatabase] 不包含名为“gettype”的方法。在 line:1 char:12 + $md.gettype <<<< () + CategoryInfo : InvalidOperation: (gettype:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound

所以,看起来我别无选择。我将为我的用例寻找解决方法。

问候,梦想家

于 2013-02-03T06:36:25.177 回答