最近我不得不面對一個類似的問題,下面的代碼幫助我通過與遠程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();
當然,你會對用戶組成員的一些常用配置,遠程安全/不安全遠程連接的服務器允許等等。 this文章可能會有所幫助。
我一直在使用Exchange EWS服務,但不幸的是,它僅用於數據和管理現有郵箱而不創建新郵件。我發現這一點,雖然不確定是否會有幫助,因爲它不是我的特長。 http://codingchris.com/2012/02/15/creating-exchange-2010-mailboxes-in-c/ – Chris