问题描述
每个 Technet-添加或删除电子邮件地址对于邮箱,使用PowerShell控制台,以下操作成功从邮箱中删除了电子邮件别名:
Per Technet - Add or Remove Email Addresses for a Mailbox, using the PowerShell console, the following successfully removes an email alias from a mailbox :
Set-Mailbox "GenMgr" -EmailAddresses @{remove="[email protected]"}
但是,通过远程运行空间调用下面的PSCommand对象会引发System.Management.Automation.RemoteException错误.
However, invoking the PSCommand object below via remote runspace throws a System.Management.Automation.RemoteException error.
command.AddCommand("Set-Mailbox");
command.AddParameter("Identity", "GenMgr");
command.AddParameter("EmailAddresses", "@{remove='[email protected]'}");
powershell.Commands = command;
powershell.Invoke();
System.Management.Automation.RemoteException:无法处理参数'EmailAddresses'上的参数转换.无法将值"@ {remove='[email protected]'}"转换为"Microsoft.Exchange.Data.ProxyAddressCollection".错误:地址'@ {remove='[email protected]'}'无效:"@ {remove='[email protected]'}"不是有效的SMTP地址.域名不能包含空格,并且必须具有前缀和后缀,例如example.com."
System.Management.Automation.RemoteException: Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "@{remove='[email protected]'}" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "The address '@{remove='[email protected]'}' is invalid: "@{remove='[email protected]'}" isn't a valid SMTP address. The domain name can't contain spaces and it has to have a prefix and a suffix, such as example.com."
在我看来,问题出在EmailAddresses参数中的'remove'指令上.
It seems to me the problem is with the 'remove' instruction in the EmailAddresses parameter.
如何在Windows 8上使用C#和PowerShell远程运行空间来使Exchange 2010删除电子邮件别名?
How do I use C# and the PowerShell remote runspace on Windows 8 to get Exchange 2010 to remove an email alias?
推荐答案
Powershell使用 @{ key = value }
语法以创建哈希表.而不是传递字符串,而是使用具有[email protected]
值的单个remove
元素传递哈希表.
Powershell uses the @{ key = value }
syntax to create a hashtable. Instead of passing a string, pass the hashtable with a single remove
element with the value of [email protected]
.
请参阅相关问题将哈希表从C#传递到powershell ,以了解更多信息.
See the related question Passing a hashtable from C# to powershell for more.
command.AddCommand("Set-Mailbox");
command.AddParameter("Identity", "GenMgr");
var addresses = new Hashtable();
addresses.Add("remove", "[email protected]");
command.AddParameter("EmailAddresses", adresses);
powershell.Commands = command;
powershell.Invoke();
这篇关于C#-通过Powershell运行空间删除Exchange电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!