title: Getting information about exchange server?
body: <p>I have an exchange server 2013 in my office. I want to find all the information about exchange server that i found using exchange management shell commands. I wants to find data like below.</p>
  
  <blockquote>
    <p>Server name, number of mailboxes, number of mail contacts, information store, storage group, recently created and deleted mailboxes, information about all the emailflow through exchange server, information about senders, receivers and many more information that i find from exchange server. </p>
  </blockquote>
  
  <p>programmatically. I want to find this information programmatically from a geographical distance using C#. I have window 7 on my machine through which, i wants to do this. I am trying this using remote power shell with C#.
  For example, i have an exchange management shell commands i.e. </p>
  
  <pre><code>Get-mailbox -resultsize unlimited -filter {$_.forwardingaddress -ne $null} | select name, userprincipalname
  </code></pre>
  
  <p>after executing the above cmdlets using exchange management shell,i have get some data, i wants to get similar information programmatically using C#.</p>
  
  <p>My code snippet </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Collections.ObjectModel;
  using System.Management.Automation; 
  using System.Management.Automation.Runspaces;
  namespace WindowsFormsApplication1
  {
   public partial class Form1 : Form
   {
     public Form1()
     {
          InitializeComponent();
     }
     private void button1_Click(object sender, EventArgs e)
     {
       string schemaURI = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
       Uri connectTo = new Uri("https://&lt;serverIP&gt;/powershell/");
       string strpassword = "password";   
       System.Security.SecureString securePassword = new System.Security.SecureString();
       foreach (char c in strpassword)
       {
           securePassword.AppendChar(c);
       }
       PSCredential credential = new PSCredential("Administrator", securePassword);
       WSManConnectionInfo connectionInfo = new WSManConnectionInfo(connectTo,schemaURI, credential);
       connectionInfo.MaximumConnectionRedirectionCount = 5;
       connectionInfo.SkipCACheck = true;
       connectionInfo.SkipCNCheck = true;
       try
       {
          Runspace remoteRunspace = RunspaceFactory.CreateRunspace(connectionInfo);
          remoteRunspace.Open();
          var command = new Command("Get-mailbox");
          command.Parameters.Add("resultsize", "unlimited");
          command.Parameters.Add("Filter", "{forwardingaddress -ne $null}");
          var pipeline = remoteRunspace.CreatePipeline();
          pipeline.Commands.Add(command);
          var results = pipeline.Invoke();    
          foreach (PSObject item in results)
          {                                                                                          
              PSPropertyInfo pinfo = (PSPropertyInfo)item.Properties["Name"];
              PSPropertyInfo prop = (PSPropertyInfo)item.Properties["userprincipalname"];
              //prop = item.Properties["Name"];
              if (pinfo != null)
              {
                    MessageBox.Show(pinfo.Value.ToString());
              }
              if (prop != null)
              {
                    MessageBox.Show(prop.Value.ToString());
              }
           }
           remoteRunspace.Dispose();
          }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message); 
        }            
      }
    }
  }
  </code></pre>
  
  <p>The line:</p>
  
  <pre><code>   remoteRunspace.Open();
  </code></pre>
  
  <p>Produce an exception given below:</p>
  
  <blockquote>
    <p><em>Connecting to remote server failed with the following error message : The WinRM client cannot process the request. The WinRM client tried to
    use Negotiate authentication mechanism, but the destination computer
    (IP:443) returned an 'access denied' error. Change the configuration
    to allow Negotiate authentication mechanism to be used or specify one
    of the authentication mechanisms supported by the server. To use
    Kerberos, specify the local computer name as the remote destination.
    Also verify that the client computer and the destination computer are
    joined to a domain. To use Basic, specify the local computer name as
    the remote destination, specify Basic authentication and provide user
    name and password. Possible authentication mechanisms reported by
    server: For more information, see the about_Remote_Troubleshooting
    Help topic</em></p>
  </blockquote>
  
  <p>How can i fix this type of exception?</p>