[英]Is there a definitive guide to programmatically creating Exchange Mailboxes remotely?
我找到了解釋如何在Exchange Server上運行PowerShell腳本的指南,但所有指南都要求該計算機是域加入的,並且大多數都似乎使用變通方法,而不是最佳實踐。
有沒有辦法使用C#.NET或VB.NET遠程連接到Exchange Server?
基本上,我想使用管理員憑據連接到我的Exchange Server(我會在程序中提供它們,加密),並使用PowerShell scriptlet創建郵箱。 就這些。
我想將應用程序作為控制台應用程序啟動,一旦我確認功能,我就可以將它實現到Web表單應用程序或MVC中。
任何意見是極大的贊賞!
我最近不得不處理類似的問題,下面的代碼幫助我通過與遠程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();
當然,您將通常配置用戶組成員資格,遠程安全/不安全遠程連接的服務器限額等。 這篇文章可能有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.