2017-05-29 85 views
0

我写了一个远程访问从asp.net应用程序的远程访问代码,以启用远程邮件使用vb.net和Exchange 2016命令运行成功从我的Visual Studio调试,但是当我把iis web服务器它给了我PowerShell远程调用。访问被拒绝从IIS

访问被拒绝

我添加的用户到服务器管理员/本地管理干部甚至orgnization管理员ASLO我更改应用程序池是一个服务器管理员用户 ,仍然得到同样的错误在网络服务器

这是代码

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; 

回答

0

我发现人的解决方案有同样的问题

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

,它会正常工作

0

1)确保Windows PowerShell是通过对远程启用(看更多here):

启用,PSRemoting

2)使确保本地操作系统防火墙不会阻止请求

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

设置用户大卫-RemotePowerShellEnabled $真

附: 出于安全原因,我永远不会运行IIS池作为您的文章中提到的本地管理员权限的帐户!

+0

PSRemoting启用 RemotePowerShellEnabled还能够为用户 为IIS池只是一个尝试我不会让它启用 –

相关问题