【问题标题】:Is there a definitive guide to programmatically creating Exchange Mailboxes remotely?是否有以编程方式远程创建 Exchange 邮箱的权威指南?
【发布时间】:2013-04-03 15:08:41
【问题描述】:

我找到了解释如何在 Exchange Server 上运行 PowerShell 脚本的指南,但所有指南都要求计算机已加入域,而且大多数指南似乎都使用了变通方法,而不是最佳实践。

有没有办法使用 C#.NET 或 VB.NET 远程连接到 Exchange Server?

基本上,我想使用管理员凭据连接到我的 Exchange Server(我将在程序中提供加密的凭据),并使用 PowerShell 脚本创建一个邮箱。仅此而已。

我想将应用程序作为控制台应用程序启动,一旦确认功能,我就可以将其实现到 Web 表单应用程序或 MVC 中。

非常感谢任何建议!

【问题讨论】:

  • 我一直在使用 Exchange EWS 服务,但不幸的是,它仅用于数据和管理现有邮箱,而不是创建新邮箱。我发现了这个,但不确定它是否会有所帮助,因为它不是我的强项。 codingchris.com/2012/02/15/…

标签: c# asp.net vb.net exchange-server


【解决方案1】:

我最近不得不处理一个类似的问题,下面的代码帮助我通过与远程 Exchange 服务器的安全连接来执行该功能。

Runspace remoteRunspace = null;
PSCredential psc = null;
// If user name is not passed used the credentials of the current farm account
if (!string.IsNullOrWhiteSpace(username))
{
    if (!string.IsNullOrWhiteSpace(domain))
        username = domain + "\\" + username;
    SecureString secpassword = new SecureString();
    if (!string.IsNullOrEmpty(password))
    {
        foreach (char c in password)
        {
            secpassword.AppendChar(c);
        }
    }
    psc = new PSCredential(username, secpassword);
}

WSManConnectionInfo rri = new WSManConnectionInfo(new Uri(RemotePowerShellUrl), PowerShellSchema, psc);
if (psc != null)
    rri.AuthenticationMechanism = AuthenticationMechanism.Credssp;
remoteRunspace = RunspaceFactory.CreateRunspace(rri);
remoteRunspace.Open();

Pipeline pipeline = remoteRunspace.CreatePipeline();
Command cmdSharePointPowershell = new Command(Commands.AddPSSnapin.CommandName);
cmdSharePointPowershell.Parameters.Add(Commands.AddPSSnapin.Name, MicrosoftSharePointPowerShellSnapIn);
pipeline.Commands.Add(cmdSharePointPowershell);
pipeline.Invoke();

当然,您会进行一些常用的用户组成员配置、远程安全/不安全远程连接的服务器允许等。 this 文章可能会有所帮助。

【讨论】:

  • 谢谢,这对我帮助很大。我现在可以通过控制台应用程序远程连接和创建用户。我会尽快发布代码。
  • @TimeBomb006 - 很高兴为您提供帮助 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-27
  • 2022-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-21
  • 1970-01-01
相关资源
最近更新 更多