1

我正在尝试从模拟特定用户的 ASPX 页面执行 Add-Mailboxpermission。来自 MSExchange 公共源的应用程序错误记录在 Web 服务器的事件查看器中。

Watson 报告即将发送到 dw20.exe 的进程 ID:2992,参数:E12、c-buddy-RTL-AMD64、08.03.0083.006、w3wp、MEDDirectory、MEDDConnectionPoolManager.BlockImpersonatedCallers、MECommon.FailFastException、c84f、08.03.0213.000 . 错误报告启用:假

使用用于执行不同 Exchange CMDlet (包括模拟调用)的相同代码,并在没有任何错误的情况下完成。

    String ErrorText = "";
    RunspaceConfiguration config = RunspaceConfiguration.Create();
    PSSnapInException warning;
    sDecryptedPwd = SecurityManager.Decrypt(AdminPassword, true);

  using (new Impersonator(AdminUserName, "domain name", sDecryptedPwd))
    {
        // Load Exchange PowerShell snap-in.
        config.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning);
        if (warning != null)
            throw warning;

        using (Runspace thisRunspace = RunspaceFactory.CreateRunspace(config))
        {
            try
            {
                thisRunspace.Open();
                using (Pipeline thisPipeline = thisRunspace.CreatePipeline())
                {
                    //Please change parameter values.
                    thisPipeline.Commands.Add("Add-MailboxPermission");
                    thisPipeline.Commands[0].Parameters.Add("Identity", sMailboxName);
                    thisPipeline.Commands[0].Parameters.Add("User", sUserName);
                    thisPipeline.Commands[0].Parameters.Add("AccessRights", sAccessRights);
                    thisPipeline.Commands[0].Parameters.Add("DomainController", sDomainController);

                    iLogManager.Info("Identity: " + sMailboxName + " User: " + sUserName + " AccessRights: " + sAccessRights + " DomainController: " + sDomainController);

                    try
                    {
                        thisPipeline.Invoke();
                        iLogManager.Info(thisPipeline.Commands[0].CommandText);
                    }
                    catch (Exception ex)
                    {
                        ErrorText = "Error: " + ex.ToString();
                    }
                    // Check for errors in the pipeline and throw an exception if necessary.
                    if (thisPipeline.Error != null && thisPipeline.Error.Count > 0)
                    {
                        StringBuilder pipelineError = new StringBuilder();
                        pipelineError.AppendFormat("Error calling Add-MailboxPermission.");
                        foreach (object item in thisPipeline.Error.ReadToEnd())
                        {
                            pipelineError.AppendFormat("{0}\n", item.ToString());
                        }

                        ErrorText = ErrorText + "Error: " + pipelineError.ToString() + Environment.NewLine;
                    }
                }
            }

            finally
            {
                thisRunspace.Close();
            }
        }
    }
    if (ErrorText == "")
        return "no error occurred.";
    else
        return ErrorText;

Exchange 是否允许模拟修改 ACL 的 Exchange CMDlet,或者我在这里做错了什么?

任何人都可以在这里帮助我,没有太多关于从 ASPX 页面模拟的 Exchange Powershell CMdlet 的信息。

4

0 回答 0