0

How should I disable "Exchange ActiveSync" using C# code while creating a new mailbox in Microsoft Exchange 2010?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Amin
  • 1
  • 1

1 Answers1

0

You can execute powershell command to disable exchange active sync from c# code.

C# code looks like this:

var command = "Get-Mailbox \"name\" | Set-CASMailbox -ActiveSyncEnabled $false";

var runspaceConfig = RunspaceConfiguration.Create();

PSSnapInException snapInException = null;
runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);

using (var runspace = RunspaceFactory.CreateRunspace(runspaceConfig))
{
    runspace.Open();

    using (var pipeline = runspace.CreatePipeline())
    {
        pipeline.Commands.AddScript(command);

        var results = pipeline.Invoke();
        // You can handle results here
    }

    runspace.Close();
}
SergeyIL
  • 575
  • 5
  • 11