我試圖從C#代碼創建/啓用Exchange 2010服務器上的郵箱。 無處不在我看到使用下面顯示的代碼的人。啓用Exchange 2010郵箱
不過,我得到以下錯誤:
術語「啓用郵箱」沒有被識別爲cmdlet,函數,腳本文件或可操作的程序的名稱。檢查名稱的拼寫,或者如果包含路徑,請驗證路徑是否正確,然後重試。
我在做什麼錯?
SecureString password = new SecureString();
string str_password = "myPassword";
string username = "myUsername";
//FQDN is ofcourse the (fully qualified) name of our exchange server..
string liveIdconnectionUri = "http://FQDN/Powershell?serializationLevel=Full";
foreach (char x in str_password)
{
password.AppendChar(x);
}
PSCredential credential = new PSCredential(username, password);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("Enable-Mailbox");
command.AddParameter("Identity", "domainname.ltd/OUName/TestAcc Jap");
command.AddParameter("Alias", "TestAccJap");
command.AddParameter("Database", "DB-Name");
powershell.Commands = command;
try
{
runspace.Open();
powershell.Runspace = runspace;
powershell.Invoke();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
runspace.Dispose();
runspace = null;
powershell.Dispose();
powershell = null;
}
可能重複http://stackoverflow.com/questions/3398056/how-do-i-programatically-create-an-exchange-2010 -Mailbox-使用-C-尖銳)。請閱讀已接受答案的第一段 - 這有幫助嗎? –
一些示例:http://busbar.blogspot.com/2010/05/exhcange-2010-using-c-and-aspnet-to.html http://blog.pedroliska.com/2011/07/28/creating-an-exchange-2010-mailbox-from-a-remote-c-program/ – jagsler
當我嘗試接受的答案的代碼時,出現以下錯誤:沒有爲Windows PowerShell版本2註冊管理單元。 – jagsler