我正在尝试执行以下操作:
StringBuilder errorList = new StringBuilder();
RunspaceConfiguration runspaceConfig = RunspaceConfiguration.Create();
PSSnapInException snapEx = null;
PSSnapInInfo psinfo = runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapEx);
Runspace runSpace = RunspaceFactory.CreateRunspace(runspaceConfig);
runSpace.Open();
Pipeline pipeLine = runSpace.CreatePipeline();
我收到以下错误:
No snap-ins have been registered for Windows PowerShell version 2.
我是 PoweShell 的新手,不确定该错误到底意味着什么。这是我需要安装的东西吗?
编辑:完整代码
///
/// Creates mailbox for the given user.
///
/// Email address of user.
public void EnableMailbox(string userEmail)
{
StringBuilder errorList = new StringBuilder();
RunspaceConfiguration runspaceConfig = RunspaceConfiguration.Create();
PSSnapInException snapEx = null;
PSSnapInInfo psinfo = runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapEx);
Runspace runSpace = RunspaceFactory.CreateRunspace(runspaceConfig);
runSpace.Open();
Pipeline pipeLine = runSpace.CreatePipeline();
if (!MailBoxAlreadyExist(userEmail, runSpace))
{
Command createMailbox = new Command("Enable-Mailbox");
createMailbox.Parameters.Add("identity", userEmail);
createMailbox.Parameters.Add("database", "Mailbox Database Name");
pipeLine.Commands.Add(createMailbox);
pipeLine.Invoke();
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
{
foreach (object item in pipeLine.Error.ReadToEnd())
{
errorList.Append(item.ToString());
errorList.Append(System.Environment.NewLine);
}
Console.WriteLine(errorList.ToString());
}
}
else
{
Console.WriteLine("Mailbox of user " + userEmail + " already exists on exchange server.");
}
pipeLine.Dispose();
runSpace.Close();
runSpace.Dispose();
}