Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

How to get Exchange 2010 database size c#

$
0
0

I'm trying to get smallest Exchange database in my Exchange 2010 server using remote session.

I successfully connect to my exchange server and get database with properties. Some of them with value, but Properties "DatabaseSize" with Null value for each of them.

Did some body be able to get database size value?

For me important to use URI to connect Exchange DAG.

Part of my code below:

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



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>