Я написал очень маленькое приложение, которое обращается к Remote Power Shell из Exchanger Server 2010 SP1 и выполняет некоторые сценарии.Вот пример кода.Все в блоке try and catch.
string insecurePassword = "mypassword";
SecureString securePassword = new SecureString();
foreach (char passChar in insecurePassword.ToCharArray())
{
securePassword.AppendChar(passChar);
}
PSCredential credential = new PSCredential("mydomain\\administrator", securePassword);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://exchange2010.domain.com/powershell?serializationLevel=Full"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
ICollection<System.Management.Automation.PSObject> results;
//The command I want to execute is Set-MailContact with some parameters.
command.AddCommand("Set-MailContact");
command.AddParameter("Identity", "SomeIdentityOfContact");
command.AddParameter("EmailAddressPolicyEnabled", false);
command.AddParameter("PrimarySmtpAddress", "myEmailAddress@domain.com");
command.AddParameter("Confirm", false);
command.AddParameter("Force", true);
powershell.Commands = command;
// open the remote runspace
runspace.Open();
// associate the runspace with powershell
powershell.Runspace = runspace;
// invoke the powershell to obtain the results
results = powershell.Invoke();
Я пытаюсь установить PrimarySmtpAddress для MailContact, но по некоторым причинам я получаю следующее исключение:
System.Management.Automation.RemoteException: не удалось обработать преобразование аргумента для параметра 'PrimarySmtpAddress'.Невозможно преобразовать значение «SMTP: myEmailAddress@domain.com» в тип «Microsoft.Exchange.Data.SmtpAddress"
Я думаю, что оно должно быть из-за сериализации / десериализации.Кто-нибудь знает, как правильно передать значение адреса электронной почты?
Любая подсказка будет высоко оценена!