Powerhell 명령에 대한 ActiveDirectory에 새 사용자를 추가 할 수있는 웹 응용 프로그램을 작성해야하며이 작업을 수행하는 방법을 모르겠습니다.C# 및 Powershell 클래스를 사용하여 ActiveDirectory Server에 원격으로 액세스하는 방법
교환 서버에서이 작업을 수행하면 작동합니다. 여기
Exchange 서버에서 연락처 추가에 대한 내 코드 :
string URL = "http://server141.test-company.com/PowerShell/";
string Schema ="http://schemas.microsoft.com/powershell/Microsoft.Exchange";
public string CreateRemoteConnectionToExchange(string UserName, string Password, string Mailbox)
{
SecureString SecurePassword = new SecureString();
string str_password = Password;
string str_username = UserName;
foreach (char x in str_password)
{
SecurePassword.AppendChar(x);
}
PSCredential cred = new PSCredential(str_username, SecurePassword);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(URL), Schema, cred);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("New-MailContact");
command.AddParameter("ExternalEmailAddress", "SMTP:" + Mailbox + MailExtension);
command.AddParameter("Name", Mailbox);
command.AddParameter("Alias", Mailbox);
command.AddParameter("FirstName", Mailbox);
command.AddParameter("Initials", "");
command.AddParameter("LastName", "");
command.AddParameter("OrganizationalUnit", OrganizationalUnit);
command.AddParameter("DomainController", configDC);
powershell.Commands = command;
try
{
runspace.Open();
powershell.Runspace = runspace;
powershell.Invoke();
return "Der Kontakt wurde Erfolgreich erstellt";
}
catch (Exception ex)
{
...
}
finally
{
runspace.Dispose();
runspace = null;
powershell.Dispose();
powershell = null;
}
}
나는 내가 액티브 디렉토리에 원격을 만들 수있는 방법을 알고 DONAT :/ 나는 URL과 스키마 문자열이 필요합니다. ActiveDirectory는 http://server137.linde-wiemann.com/에 있습니까? = OU = NPS, OU = 서비스, DC는 = 테스트 기업, DC = COM 또는 LDAP : // OU = NPS, OU = 서비스, DC = 테스트 기업, DC = COM
모두가 나에게 도와 줄 수