如何以编程方式修改 Exchange 用户的 'mailbox features'?

How can i modify 'mailbox features' on an Exchange user programatically?

所以我真正需要做的是在 Microsoft Exchange 中对特定用户禁用 Webmail 和 ActiveSync 'mailbox features'。我已经研究过它的 powershell 脚本,但我并不真正熟悉 PS 所以我宁愿尽可能不使用它。

我可以专门使用 ExchangeService 和 EWS 访问服务器和邮件

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

        service.AutodiscoverUrl("user@domain.com");

        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(10));

        foreach (Item item in findResults.Items)
        {
            Console.WriteLine(item.Subject);
        }

但是我不知道如何找到邮箱功能。任何帮助将不胜感激!

您使用的是什么版本的 Exchange?您所说的功能并非真正 "mailbox features",但传输设置和所有 PowerShell cmdlet 运行 针对 CAS 服务器

Set-CASMailbox -Identity "John Smith" -OWAEnabled $false;
Set-CASMailbox -Identity "John Smith" -ActiveSyncEnabled $false;

/叶夫根尼

我在互联网上的某处找到了这个我实际上不记得在哪里。我只是修改它以达到我的目的。

        RunspaceConfiguration runspaceConfig = RunspaceConfiguration.Create();
        Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfig);
        runspace.Open();
        Pipeline pipeline = runspace.CreatePipeline();

        string serverFqdn = "server";
        pipeline.Commands.AddScript(string.Format("$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://{0}/PowerShell/ -Authentication Kerberos", serverFqdn));
        pipeline.Commands.AddScript("Import-PSSession $Session");
        pipeline.Commands.AddScript("Set-CASMailbox -Identity '" + userID + "' -OWAEnabled $true");
        pipeline.Commands.AddScript("Set-CASMailbox -Identity '" + userID + "' -ActiveSyncEnabled  $true");
        pipeline.Commands.Add("Out-String");
        Collection<PSObject> results = pipeline.Invoke();
        runspace.Close();

        if (pipeline.Error != null && pipeline.Error.Count > 0)
        {
            // failed
        }
        else
        {
            // Success
        }

        runspace.Dispose();
        pipeline.Dispose();