C#으로 Exchange 사서함을 만들려고합니다. 다음 코드는 오류를 생성하지 않습니다, 그러나 또한 내가 기대하는 것처럼 사서함을 만들 나타나지 않습니다Exchange 사서함을 만드는 방법은 무엇입니까?
private void buttonCreateUser_Click(object sender, EventArgs e)
{
Boolean Success = CreateUser(textBoxFirstName.Text, textBoxLastName.Text,
textBoxAlias.Text, textBoxPassword.Text,
comboBoxDomain.SelectedItem.ToString(),
comboBoxOrganizationalUnit.SelectedItem.ToString());
if (Success)
{
labelStatus.Text = "User Created";
}
else
{
labelStatus.Text = "There Is Some Error";
}
}
public Boolean CreateUser(string FirstName, string LastName, string Alias,
string PassWord, string DomainName, string OrganizationalUnit)
{
string Name = FirstName + " " + LastName;
string PrincipalName = FirstName + "." + LastName + "@" + DomainName;
Boolean success = false;
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
SecureString spassword = new SecureString();
spassword.Clear();
foreach (char c in PassWord)
{
spassword.AppendChar(c);
}
PSSnapInException snapInException = null;
PSSnapInInfo info = rsConfig.AddPSSnapIn(
"Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);
Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
myRunSpace.Open();
Pipeline pipeLine = myRunSpace.CreatePipeline();
Command myCommand = new Command("New-MailBox");
myCommand.Parameters.Add("Name", Name);
myCommand.Parameters.Add("Alias", Alias);
myCommand.Parameters.Add("UserPrincipalName", PrincipalName);
myCommand.Parameters.Add("Confirm", true);
myCommand.Parameters.Add("SamAccountName", Alias);
myCommand.Parameters.Add("FirstName", FirstName);
myCommand.Parameters.Add("LastName", LastName);
myCommand.Parameters.Add("Password", spassword);
myCommand.Parameters.Add("ResetPasswordOnNextLogon", false);
myCommand.Parameters.Add("OrganizationalUnit", OrganizationalUnit);
pipeLine.Commands.Add(myCommand);
pipeLine.Invoke();
myRunSpace.Dispose();
success = true;
return success;
}
나는 오류가 발생하지 않는, 그래서 내가 모르는 잘못하고있다.
내가 이것도 알라를 들어 웹 서비스를 사용하고
업데이트 나는하지 WebService에와 작동 윈도우 응용 프로그램과 같은 코드를 실행, 그러나? Exchange Server를 변경해야합니까? Get-MailBox가있는 MailBox 정보를 얻을 수 있지만 New-MailBox는 사용자를 만들 수는 없지만.
구축중인 POSH 명령이 예상 한대로 작동합니까? –
@ M.Babcock 사용자가 사서함에 추가되지 않았습니다. – Hiren
문제를 복잡하게 만드는 API로 동적으로 빌드하기 전에 POSH 명령의 세부 사항을 수동으로 작성하십시오. –