|
Создание почтового ящика на Exchange 2010
|
|||
---|---|---|---|
#18+
Добрый день! Есть фрагмент кода, который при создании пользователя в AD заодно создаёт потом для него почтовый ящик на Exchange 2010, выполняя командлет Enable-Mailbox. SecureString password = new SecureString(); string str_password = "88Qwerty"; string username = "testmom@samspace.ru"; string liveIdconnectionUri = " http://saab01.samspace.ru/powershell?serializationLevel=Full"; // foreach (char x in str_password) { password.AppendChar(x); } PSCredential credential = new PSCredential(username, password); // Set the connection Info WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), " http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos; connectionInfo.OpenTimeout = 1 * 30 * 1000; connectionInfo.OperationTimeout = 1 * 30 * 1000; // create a runspace on a remote path // the returned instance must be of type RemoteRunspace Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo); PowerShell powershell = PowerShell.Create(); PSCommand command = new PSCommand(); command.AddCommand("Enable-Mailbox"); command.AddParameter("Identity", "SAMSPACE\\"+s_login); command.AddParameter("Alias", s_login); if (c_cont.Text == "TSSKB-PROGRESS") { command.AddParameter("Database", "progress mailbox database"); } if (c_cont.Text == "OPTEKS") { command.AddParameter("Database", "opteks mailbox database"); } if (c_cont.Text == "SPEKTR") { command.AddParameter("Database", "spektr mailbox database"); } powershell.Commands = command; try { // open the remote runspace runspace.Open(); // associate the runspace with powershell powershell.Runspace = runspace; // invoke the powershell to obtain the results powershell.Invoke(); } catch (Exception ex) { MessageBox.Show("Ошибка. Почтовый ящик не создан."+ex.Message); } finally { MessageBox.Show("Почтовый ящик для " + s_login + " успешно создан."); // dispose the runspace and enable garbage collection runspace.Dispose(); runspace = null; // Finally dispose the powershell and set all variables to null to free // up any resources. powershell.Dispose(); powershell = null; } Так вот, этот код работает, но есть вопросы: 1) Под каким пользователем на самом деле происходит подключение - под testmom@samspace.ru или под текущим, если connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos; 2) Если из блока finally убираю MessageBox.Show("Почтовый ящик для " + s_login + " успешно создан."), то выполнение командлета не происходит, как будто он "застревает" 3) У одного из 10-ти пользователей в среднем почтовые ящики не создаются, при этом в блок catch перехода не происходит. Можете прокомментировать ситуацию и усовершенствовать этот код. Заранее благодарен. ... |
|||
:
Нравится:
Не нравится:
|
|||
26.10.2013, 13:27 |
|
Создание почтового ящика на Exchange 2010
|
|||
---|---|---|---|
#18+
Решил проблему. Вот исправленная версия. string liveIdconnectionUri = " http://saab01.samspace.ru/powershell?serializationLevel=Full"; PSCredential credential = (PSCredential)(null); WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), " http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos; connectionInfo.OpenTimeout = 1 * 30 * 1000; connectionInfo.OperationTimeout = 1 * 30 * 1000; Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo); PipeLine pLine = runspace.CreatePipeLine(); Command command = new Command(); command.Parameters.Add("Enable-Mailbox"); command.Parameters.Add("Identity", s_login); command.Parameters.Add("Alias", s_login); if (c_cont.Text == "TSSKB-PROGRESS") { command.Parameters.Add("Database", "progress mailbox database"); } if (c_cont.Text == "OPTEKS") { command.Parameters.Add("Database", "opteks mailbox database"); } if (c_cont.Text == "SPEKTR") { command.Parameters.Add("Database", "spektr mailbox database"); } pLine.Commands.Add(command); try { // open the remote runspace runspace.Open(); Collection<PSObject> res=pLine.Invoke(); } catch (Exception ex) { MessageBox.Show("Ошибка. Почтовый ящик не создан."+ex.Message); } finally { //MessageBox.Show("Почтовый ящик для " + s_login + " успешно создан."); // dispose the runspace and enable garbage collection pLine=null; runspace.Dispose(); runspace = null; } Подключается под текущим пользователем. MessageBox закомментирован. Проблем не наблюдается. ... |
|||
:
Нравится:
Не нравится:
|
|||
26.10.2013, 16:06 |
|
Создание почтового ящика на Exchange 2010
|
|||
---|---|---|---|
#18+
Ещё одно уточнение, если требуется создавать одновременно пользователя и почтовый ящик на Exchange, то предпочтительнее использовать командлет New-MailBox вместо Enable-MailBox, т.к. последний в этом случае может отработать, не создав ящик. ... |
|||
:
Нравится:
Не нравится:
|
|||
02.11.2013, 09:07 |
|
|
start [/forum/topic.php?fid=20&msg=38450774&tid=1403756]: |
0ms |
get settings: |
17ms |
get forum list: |
13ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
68ms |
get topic data: |
8ms |
get forum data: |
2ms |
get page messages: |
34ms |
get tp. blocked users: |
1ms |
others: | 12ms |
total: | 161ms |
0 / 0 |