是否有一个以编程方式远程创建Exchange邮箱的权威指南?

5 c# vb.net asp.net exchange-server

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

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

基本上,我想使用管理员凭据连接到我的Exchange Server(我会在程序中提供它们,加密),并使用PowerShell scriptlet创建邮箱.就这些.

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

任何意见是极大的赞赏!

Muh*_*ani 6

我最近不得不处理类似的问题,下面的代码帮助我通过与远程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();
Run Code Online (Sandbox Code Playgroud)

当然,您将通常配置用户组成员资格,远程安全/不安全远程连接的服务器限额等.这篇文章可能有帮助.