如何获取Exchange 2010数据库大小

时间:2014-12-16 08:09:54

标签: c# exchange-server-2010

我正在尝试使用远程会话在 Exchange 2010 服务器中获取最小的 Exchange 数据库。

我成功连接到我的Exchange服务器并使用属性获取数据库。其中一些具有价值,但属性 DatabaseSize 具有Null值。

某个机构是否能够获得数据库大小值? 我的部分代码如下:

static void Main(string[] args)
    {
        string exchangePowershellRPSURI = "http://my.domain/powershell?serializationLevel=Full";

        PSCredential credentials = (PSCredential)null;
        //Provides the connection information that is needed to connect to a remote runspace
        // Prepare the connection           
        WSManConnectionInfo connInfo = new WSManConnectionInfo((new Uri(exchangePowershellRPSURI)),
            "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
        connInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos; 
        connInfo.SkipCACheck = true;
        connInfo.SkipCNCheck = true;
        connInfo.SkipRevocationCheck = true;

        // Create the runspace where the command will be executed           
        Runspace runspace = RunspaceFactory.CreateRunspace(connInfo);

        // Add the command to the runspace's pipeline           
            runspace.Open();

            //Represents the base functionality of a pipeline that can be used to invoke commands
            Pipeline pipeline = runspace.CreatePipeline();

            Command getMDB = new Command("Get-MailboxDatabase");
            getMDB.Parameters.Add("Identity", "*");
            getMDB.Parameters.Add("Status", null);

            pipeline.Commands.Add(getMDB);

            Collection<PSObject> select = pipeline.Invoke();


        if (select.Count > 0)
        {

             foreach(PSObject obj in select)
            {
                var db = obj.Properties["DatabaseSize"].Value;
                string name = obj.Properties["Name"].Value.ToString();
                Console.WriteLine("Database Name: {0} Size: {1}", name, db);
            }

        }

        else
        {
             Console.WriteLine("Failed to create email account");
        }
        runspace.Dispose();

        Console.ReadLine();     
    }

1 个答案:

答案 0 :(得分:0)

我找到了解决方案 在getMDB.Parameters.Add中需要Status参数来改变&#34; null&#34;的值。 to&#34; true&#34;

getMDB.Parameters.Add("Status", null);