下面是我使用的代碼。我無法使用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:[email protected],[email protected]");
powershell.Commands = command2;
powershell.Invoke();
我已經能夠成功運行此代碼時,輸入每個電子郵件地址自己。 –
雖然參數狀態我可以插入多個值 - 參數值1,值2等,它看起來像它看到它作爲一個完整的地址使其無效。 –