下面是我正在使用的代码。我无法使用 powershell Emailaddresses 参数添加多个地址。如果我只输入一个电子邮件地址,该代码就可以正常工作,但是一旦我在下面的代码中添加两个地址,它就会返回异常,指出无效的 smtp 地址。
PSCredential credential = new PSCredential(username, password);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
runspace.Open();
powershell.Runspace = runspace;
var secure = new SecureString();
foreach (char c in textBox5.Text)
{
secure.AppendChar(c);
}
PSCommand command2 = new PSCommand();
command2.AddCommand("Set-Mailbox");
command2.AddParameter("Identity", "lferrigno");
command2.AddParameter("EmailAddressPolicyEnabled", 0);
command2.AddParameter("EmailAddresses", "SMTP:lferrigno@sscincorporated.com,lou.ferrigno@altegrahealth.com");
powershell.Commands = command2;
powershell.Invoke();