2017-05-29 118 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池只是一個嘗試我不會讓它啓用 –