在C#中与Exchange服务器通信的错误 [英] Errors for communicate with exchange server in C#

查看:54
本文介绍了在C#中与Exchange服务器通信的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是Exchange的新成员 请告诉我我哪里出错了。

I am new in Exchange development please let me know where i am going wrong.

I我正在尝试编写一个代码,该代码将在C#中执行以下代码;

I am trying to write a code which will execute following code in C#;

1。   Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010

1.  Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010

  ;

2。 get-credential

2. get-credential

 

 

3。新组织-name NiteenOrg -DomainName NiteenOrg.com -ProgramId HostingSample -OfferId 2 -location en-US -AdministratorPassword
mycustompassword

3. New-organization -name NiteenOrg -DomainName NiteenOrg.com -ProgramId HostingSample -OfferId 2 -location en-US -AdministratorPassword mycustompassword

 

我正在使用以下代码C#函数,

and I am using following code C# function for this,

 

 


public static string RunScript(string scriptText)
    {
      RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
      PSSnapInException snapInException = null;
      PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);

      // create Powershell runspace
      Runspace runspace = RunspaceFactory.CreateRunspace(rsConfig);

      // open it
      runspace.Open();

      // create a pipeline and feed it the script text
      Pipeline pipeline = runspace.CreatePipeline();

      pipeline.Commands.AddScript(scriptText);
      
      pipeline.Commands.Add("Out-String");

      // execute the script
      Collection<PSObject> results = pipeline.Invoke();

      // close the runspace
      runspace.Close();

      // convert the script result into a single string
      StringBuilder stringBuilder = new StringBuilder();
      foreach (PSObject obj in results)
      {
        stringBuilder.AppendLine(obj.ToString());
      }

      return stringBuilder.ToString();
    }

推荐答案

Nitin,

Nitin,

  ;您使用的是哪个版本的Exchange?我在从Web服务向Exchange 2010发送Enable-Mailbox命令时遇到问题,但错误是另一个错误。您可以查看我的帖子并修改代码以满足您的需求。这是
链接

  What version of Exchange you are using? I had problems sending Enable-Mailbox command from my webservice to Exchange 2010 but the error was a different one. You can have a look at my post and modify the code to fit to your needs. Here is the link

http://social.technet.microsoft.com/Forums/en/exchangesvrdevelopment/thread/4c5015df-59fd-49db-8e6a-411f08ee2f3e

如果您正在尝试使用Exchange 2010,然后确保在运行代码的框中安装了Exchange 2010管理工具。这是Exchange远程Powershell通信的基本要求。

If you are trying it with Exchange 2010, then make sure you have Exchange 2010 Management tool installed on the box where you are running your code. This is basic requirement for Exchange Remote Powershell communication.

Shesh


这篇关于在C#中与Exchange服务器通信的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆