編輯 我得到它差不多,現在有錯誤消息,它無法找到交換DB。我在不同的服務器上運行服務,然後Exchange,所以我認爲我必須使用UNC路徑。 MyServer01 \第一個存儲組\郵箱Database.edb不工作,雖然...通過遠程Exchange 2007服務器上的webservice爲用戶創建郵箱。 (C#)
嗨! 我在這裏感到很沮喪,感覺頭痛很大,我幾乎要把我的電腦扔出窗外...
這是問題,我想創建一個新用戶通過Sharepoint的Active Directory,在Sharepoint列表下面運行一個工作流程,它捕獲變量並將它們發送到一個web服務,該服務在活動目錄中創建用戶。這工作完美,但用戶還需要一個郵箱。 那麼,我們該怎麼做?我們將郵件屬性設置爲所需的電子郵件地址並找到屬性「創建郵箱」....說出來吧?它在哪裏? NOOOOOESSS它不存在了,MS決定它需要更復雜,現在唯一的方法就是使用PowerShell的廢話...
所以這就是爲什麼我在這裏,我搜索了一些關於這方面的信息,發現了一些代碼應該做的伎倆,但是,那就是我卡住,web服務不運行在Exchange服務器上,但在不同的服務器上,web服務需要連接到交換服務器來運行powershellshizzle ...可以「找不到任何這信息,找不到任何實例等等...
HLEP ... F1 ...等
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell.Commands;
using System.Web.Services;
using System.DirectoryServices;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public void CreateADUser(string domain, string domainPostFix, string firstName, string emailaddress, string lastName, string department, string loginName, string password)
{
DirectoryEntry AD = null;
DirectoryEntry NewUser = null;
AD = new DirectoryEntry("LDAP://OU=Users,DC=" + domain + ",DC=" + domainPostFix);
NewUser = AD.Children.Add("CN=" + firstName + " " + lastName, "user");
NewUser.Properties["samAccountName"].Add(loginName);
NewUser.Properties["name"].Add(firstName + " " + lastName);
NewUser.Properties["displayname"].Add(firstName + " " + lastName);
NewUser.Properties["givenName"].Add(firstName);
NewUser.Properties["sn"].Add(lastName);
NewUser.Properties["userprincipalname"].Add(loginName + "@" + domain + "." + domainPostFix);
NewUser.CommitChanges();
NewUser.Invoke("SetPassword", new object[] { password });
NewUser.CommitChanges();
// E-mail shizzle, don't understand it yet, hopefully it works, if not, don't blame me -Erik
RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
PSSnapInException PSException = null;
PSSnapInInfo info = runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out PSException);
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command command = new Command("New-Mailbox");
command.Parameters.Add("Name", "TestName");
//Enabling user account
int val = (int)NewUser.Properties["userAccountControl"].Value;
NewUser.Properties["userAccountControl"].Value = val & ~0x2;
NewUser.CommitChanges();
NewUser.Close();
}