【问题标题】:PowerShell remote call. Access is denied from IISPowerShell 远程调用。 IIS 拒绝访问
【发布时间】:2017-10-29 12:39:59
【问题描述】:

我为从 asp.net 应用程序中的 exchange powershell 远程访问编写了一个代码,以使用 vb.net 和 exchange 2016 启用远程邮件,该命令从我的 Visual Studio 调试中成功运行,但是当我放入 iis Web 服务器时,它给了我

访问被拒绝

我将用户添加到服务器管理员/本地管理员甚至组织管理员中,并且我将应用程序池更改为服务器管理员用户 并且仍然在网络服务器中得到同样的错误

这是代码

string back = "";
            try
            {
                string ServerUri = "http://{server}/PowerShell/";
                //use one of CAS servers
                string SchemaUri = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
                string userName = AccountOperatorLogon;
                //user must be member of "Recipient Management" group to create Mailboxes
                System.Security.SecureString password = new System.Security.SecureString();
                foreach (char x in AccountOperatorPassword)
                {
                    password.AppendChar(x);
                }
                string onmicrosoftemail = Email.ToLower().Replace("mail.com", "mail.onmicrosoft.com");
                PSCredential PSCredential = new PSCredential(userName, password);
                WSManConnectionInfo ConnectionInfo = new WSManConnectionInfo(new Uri(ServerUri), SchemaUri, PSCredential);
                ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
                Runspace RemoteRunspace = RunspaceFactory.CreateRunspace(ConnectionInfo);
                PowerShell RemotePowerShell = PowerShell.Create();
                RemotePowerShell.AddCommand("Enable-RemoteMailbox");
                RemotePowerShell.AddParameter("Identity", samAccount);
                RemotePowerShell.AddParameter("RemoteRoutingAddress", onmicrosoftemail);
                // Open the remote runspace on the server.
                RemoteRunspace.Open();
                // Associate the runspace with the Exchange Management Shell.
                RemotePowerShell.Runspace = RemoteRunspace;
                var result = RemotePowerShell.Invoke();
                foreach (PSObject RSLT in result)
                {
                    back += RSLT.ToString();
                }
                RemoteRunspace.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return back;

【问题讨论】:

    标签: c# asp.net office365 exchange-server


    【解决方案1】:

    1.) 确保已启用 Windows PowerShell 以通过远程处理(请参阅更多 here):

    启用-PSRemoting

    2.) 确保本地操作系统防火墙没有阻止请求

    3.) 根据您希望执行的操作,您需要授予一些必要的权限。对于MS Exchange

    Set-User David -RemotePowerShellEnabled $True

    附言 出于安全原因,我永远不会将 IIS 池作为具有您帖子中提到的本地管理员权限的帐户运行!

    【讨论】:

    • PSRemoting 已启用 RemotePowerShellEnabled 也为 iis 池的用户启用,只是为了尝试,我不会这样做
    【解决方案2】:

    我找到了任何有相同问题的人的解决方案

    1. 将用户创建为(收件人管理组)的成员
    2. IIS 更改(用于 Exchange 服务器) 导航到 IIS 管理器 |默认网站 |电源外壳 更改物理路径:C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\PowerShell 到:C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\PowerShell
    3. 更改后:IISRESET

    它会正常工作

    【讨论】:

    • 我们的环境中确实存在同样的问题。您能否更准确地解释问题以及为什么此配置更改会有所帮助?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2012-10-02
    • 2010-12-26
    相关资源
    最近更新 更多