Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中以编程方式从MailboxDatabase获取数据库副本(在C#中包装ExchangeMagementShell cmdlet)?_C#_Powershell_Powershell 2.0_Exchange Server 2010_Powershell Remoting - Fatal编程技术网

如何在C#中以编程方式从MailboxDatabase获取数据库副本(在C#中包装ExchangeMagementShell cmdlet)?

如何在C#中以编程方式从MailboxDatabase获取数据库副本(在C#中包装ExchangeMagementShell cmdlet)?,c#,powershell,powershell-2.0,exchange-server-2010,powershell-remoting,C#,Powershell,Powershell 2.0,Exchange Server 2010,Powershell Remoting,我将ExchangeManagementShell cmdlet包装在C#中,以编程方式执行cmdlet(请参阅__http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/155504b3-ffe3-4bdf-887a-1e61842a8697) 我知道mailboxdatabase的“DatabaseCopy”属性包含副本。但我不知道如何解析反序列化数据库复制数据以获取属性 请参阅下面的代码片段。我

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

我知道mailboxdatabase的“DatabaseCopy”属性包含副本。但我不知道如何解析反序列化数据库复制数据以获取属性

请参阅下面的代码片段。我基本上是在分析Get-MailboxDatabase cmdlet结果以获得我们感兴趣的属性。不知道如何从中获取数据库副本

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

即使是从PowerShell,它们也以普通字符串的形式出现

PS C:>$md.type PS C:>$md.DatabaseCopies.gettype()

IsPublic IsSerial名称基类型 -------- -------- ---- -------- True ArrayList System.Object

PS C:>$md.DatabaseCopies[0]。gettype()

IsPublic IsSerial名称基类型 -------- -------- ---- -------- 真字符串系统。对象

PS C:>$md.gettype() 方法调用失败,因为[Deserialized.Microsoft.Exchange.Data.Directory.SystemConfiguration.MailboxDatabase]d oesn不包含名为“gettype”的方法。 第1行字符:12
+$md.gettype你找到工作了吗?我也有同样的问题。无法获取c代码中的数据库副本。