如何使用C#创建新邮箱时禁用“Exchange ActiveSync”

时间:2013-06-03 08:28:53

标签: exchange-server exchange-server-2010

在Microsoft Exchange 2010中创建新邮箱时,如何使用C#代码禁用“Exchange ActiveSync”?

1 个答案:

答案 0 :(得分:0)

您可以执行powershell命令以禁用来自c#代码的交换活动同步。

C#代码如下所示:

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