title: Disable ActiveSync using C#
body: <p>I am trying to use C# to disable ActiveSync mailboxes on Exchange Server 2007 (and soon to be 2013 which is probably completely different) using powershell.  The first command works to set the Allowed Device IDs.  The second to turn off activesync does not.  Am I specifying it incorrectly?</p>
  
  <pre><code>RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
  
  PSSnapInException PSException = null;
  PSSnapInInfo info = runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out PSException);
  
  Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);
  
  runspace.Open();
  
  Pipeline pipeline = runspace.CreatePipeline();
  
  Command command = new Command("Set-CASMailbox");
  
  command.Parameters.Add("Identity", username);
  command.Parameters.Add("ActiveSyncAllowedDeviceIDs", "\"BLOCKED\"");
  pipeline.Commands.Add(command);
  
  command = new Command("Set-CASMailbox");
  command.Parameters.Add("Identity", username);
  command.Parameters.Add("ActiveSyncEnabled", false);
  
  pipeline.Commands.Add(command);
  
  Collection&lt;PSObject&gt; result = pipeline.Invoke();
  </code></pre>