【发布时间】:2011-11-07 14:01:44
【问题描述】:
我正在寻找一种为会议室(邮箱)设置 AcceptMessagesOnlyFrom 的方法。我正在使用 C# 代码(Windows 应用程序)执行 Exchange 2007 Powershell 命令。
这是我的代码
RunspaceConfiguration rc = RunspaceConfiguration.Create();
PSSnapInException snapEx = null;
PSSnapInInfo info = rc.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapEx);
Runspace r = RunspaceFactory.CreateRunspace(rc);
r.Open();
RunspaceInvoke ri = new RunspaceInvoke(r);
string str = "Set-Mailbox -Identity '" + MeetingRoomName + "' -AcceptMessagesOnlyFrom ((Get-Mailbox -identity '" + MeetingRoomName + "').AcceptMessagesOnlyFrom + " + strUser + ")";
ICollection<PSObject> results = ri.Invoke(str);
此命令在 powershell 中运行良好,但在 C# 中运行不正常。代码执行时没有任何错误,但用户没有被添加到列表中。
任何帮助将不胜感激。
【问题讨论】:
-
是不是需要以管理员身份运行VS或者C#?
-
其实我对此了解不多。请告诉我如何以管理员身份运行 VS 或 C#?
标签: c# powershell exchange-server