2012-02-23 167 views
1

标题几乎可以解释这一切。我有一个C#应用程序不在Exchange Server上运行。我需要能够创建邮箱。我试图用this教程,但它需要PowerShell的IIS虚拟目录中,以:在C#中远程Exchange 2010服务器上创建Exchange邮箱#

  1. 不需要SSL
  2. 允许基本身份验证

哪些事情,我们不能这样做。这使我有两种可能的解决方案。有没有办法修改上面列出的教程,以便不需要这两个限制,还是有办法在不使用Power Shell的情况下执行此操作?

下面是代码,如果你不觉得喜欢去的链接:

 

using System; 
using System.Security; 
using System.Management.Automation; 
using System.Management.Automation.Runspaces; 

namespace PowerShellTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      // Prepare the credentials that will be used when connecting 
      // to the server. More info on the user to use on the notes 
      // below this code snippet. 
      string runasUsername = @"username"; 
      string runasPassword = "password"; 
      SecureString ssRunasPassword = new SecureString(); 
      foreach (char x in runasPassword) 
       ssRunasPassword.AppendChar(x); 
      PSCredential credentials = 
       new PSCredential(runasUsername, ssRunasPassword); 

      // Prepare the connection 
      var connInfo = new WSManConnectionInfo(
       new Uri("http://ServersIpAddress/PowerShell"), 
       "http://schemas.microsoft.com/powershell/Microsoft.Exchange", 
       credentials); 
      connInfo.AuthenticationMechanism = 
       AuthenticationMechanism.Basic; 

      // Create the runspace where the command will be executed 
      var runspace = RunspaceFactory.CreateRunspace(connInfo); 

      // generate the command parameters 
      var testNumber = 18; 
      var firstName = "Test"; 
      var lastName = "User" + testNumber; 
      var username = "tuser" + testNumber; 
      var domainName = "pedro.test.local"; 
      var password = "ActiveDirectoryPassword1234"; 
      var ssPassword = new SecureString(); 
      foreach (char c in password) 
       ssPassword.AppendChar(c); 

      // create the PowerShell command 
      var command = new Command("New-Mailbox"); 
      command.Parameters.Add("Name", firstName + " " + lastName); 
      command.Parameters.Add("Alias", username); 
      command.Parameters.Add(
       "UserPrincipalName", username + "@" + domainName); 
      command.Parameters.Add("SamAccountName", username); 
      command.Parameters.Add("FirstName", firstName); 
      command.Parameters.Add("LastName", lastName); 
      command.Parameters.Add("Password", ssPassword); 
      command.Parameters.Add("ResetPasswordOnNextLogon", false); 
      command.Parameters.Add(
       "OrganizationalUnit", "NeumontStudents"); 

      // Add the command to the runspace's pipeline 
      runspace.Open(); 
      var pipeline = runspace.CreatePipeline(); 
      pipeline.Commands.Add(command); 

      // Execute the command 
      var results = pipeline.Invoke(); 

      runspace.Dispose(); 

      if (results.Count > 0) 
       Console.WriteLine("SUCCESS"); 
      else 
       Console.WriteLine("FAIL"); 

     } 
    } 
} 

 

回答

1

您可以设置很多不同AuthenticationMechanism

访问MSDN网站所谓的运行空间用于使用代码样品:

  • 基本认证(这是在实施例中使用)
  • 证书验证
  • Kerberos身份验证
  • 协商的身份验证

http://msdn.microsoft.com/en-us/library/ff326159(v=exchg.140).aspx

在任何情况下,没有必要放弃对PowerShell的,只是还没有。

1

该博客文章的代码有点不合适。 Pipeline类是创建命令的一种过于复杂的方式,其编写方式涉及创建一对运行空间(一个本地,一个远程),而不仅仅是远程运行空间。

此外,IIS中的“基本”和“http”并不表示“在PowerShell中没有安全性和不加密”。通过WinRM层发送的所有内容都是默认加密的。来自Exchange团队的

This Link涵盖了在C#中完成此操作的正确方法。

所以:

  • 您不必担心IIS“基本”,因为有另一层安全。
  • 可以减少你的代码了一半,使之更快,如果你使用C#从Exchange团队

而且是100%一清二楚:

你不能管理Exchange 2010中远程,除了通的PowerShell 。

希望对此有所帮助

相关问题