我正在制定一個解決方案,用戶可以使用Outlook Web Access通過網頁清除通過Exchange 2010註冊的移動設備,而不是一個選項。 我已在我的開發計算機上安裝了Exchange管理工具,並且應用程序池正在使用具有執行命令(分配的角色組「收件人管理」)所需權限的標識。我使用下面的代碼來執行溼巾從ASP.NET應用程序調用exchange activesync cmdlet
string deviceId = "deviceid";
string username = "username";
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);
if(snapInException != null)
throw snapInException;
using(var runspace = RunspaceFactory.CreateRunspace(new MyPowershellHost(), rsConfig))
{
runspace.Open();
using(var pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript(@". ""C:\Program files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1""");
pipeline.Commands.AddScript("Connect-ExchangeServer -auto");
pipeline.Invoke();
}
ActiveSyncDeviceConfiguration actualDevice;
using(var pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript(string.Format("Get-ActiveSyncDeviceStatistics -Mailbox {0}", username));
var result = pipeline.Invoke();
actualDevice = result.Select(x => x.BaseObject as ActiveSyncDeviceConfiguration).Where(x => x.DeviceID.EndsWith(deviceId)).SingleOrDefault();
}
if(actualDevice != null)
{
var identity = actualDevice.Identity as ADObjectId;
using(var pipeline = runspace.CreatePipeline())
{
var cmd = new Command("Clear-ActiveSyncDevice");
cmd.Parameters.Add("Identity", identity.DistinguishedName);
pipeline.Commands.Add(cmd);
pipeline.Invoke();
}
}
}
我可以當用戶帳戶被添加在機器上的本地管理員並登錄到Windows,此工作。我可以接受,如果用戶必須是本地管理員,但讓用戶不斷登錄對於服務器應用程序來說並不實用。 MyPowershellHost類只是一個基本的主機實現,允許RemoteExchange.ps1腳本在與UI進行交互後運行。
我無法弄清楚用戶是否需要額外的特權,或者我只是做錯了。