2017-05-24 311 views
0

我寫了一個遠程訪問從asp.net應用程序的遠程訪問代碼,以啓用遠程郵件使用vb.net和交換2016 該命令從我的visual studio調試成功運行 ,但是當我把iis Web服務器它給我PowerShell遠程調用。訪問被拒絕從網絡服務器

連接到遠程服務器「」,出現以下錯誤消息 失敗:訪問被拒絕

這是代碼

Function enableRemoteEmail(ByVal samaccount As String, ByVal email As String) As String 
    Dim ServerUri As String = "http://{mailserver}/powershell" 
    Dim SchemaUri As String = "http://schemas.microsoft.com/powershell/Microsoft.Exchange" 
    Dim userName As String = AccountOperatorLogon 
    Dim password As New System.Security.SecureString 
    For Each x As Char In AccountOperatorPassword 
     password.AppendChar(x) 
    Next 

    Dim PSCredential As New PSCredential(userName, password) 
    Dim ConnectionInfo As WSManConnectionInfo = New WSManConnectionInfo(New Uri(ServerUri), SchemaUri, PSCredential) 
    ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic 
    Dim RemoteRunspace As Runspace = RunspaceFactory.CreateRunspace(ConnectionInfo) 
    Dim RemotePowerShell As PowerShell = PowerShell.Create 
    RemotePowerShell.AddCommand("Enable-RemoteMailbox") 
    RemotePowerShell.AddParameter("Identity", samaccount) 
    RemotePowerShell.AddParameter("RemoteRoutingAddress",email) 
    RemotePowerShell.AddParameter("Credential", PSCredential) 

    ' Open the remote runspace on the server. 
    RemoteRunspace.Open() 
    ' Associate the runspace with the Exchange Management Shell. 
    RemotePowerShell.Runspace = RemoteRunspace 
    Dim TheResult As Collection(Of PSObject) 
    Dim TheResultString As String = "" 
    TheResult = RemotePowerShell.Invoke 
    For Each RSLT As PSObject In TheResult 
     TheResultString += RSLT.ToString() + "<br/>" 
    Next 
    RemoteRunspace.Close() 
    ' Invoke the Exchange Management Shell to run the command. 
    Return TheResultString 
End Function 
+0

可能是一個權限問題:https://support.microsoft.com/en-us/help/2905767/-access-is-denied-error-when-you-connect-to-exchange-online-by-using-remote-windows-powershell – N0Alias

+0

我在用戶PSCredential下運行代碼調試模式,但在Web服務器不工作 –

+0

有時Web服務器被鎖定在DMZ中,可能沒有連接到域,所以引用AccountOperator登錄 和AccountOperatorPassword可能是問題。 – N0Alias

回答

1

我發現人的解決方案有同樣的問題

  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

男人你救了我,我掙扎了近3天的這個問題,沒有找到解決方案,我說好的,是時候在stackoverflow中問一個問題,然後我在建議的答案列表中看到了這個,哇 - 這是工作,非常感謝,我編輯你的問題與完整的錯誤信息,所以它會更容易找到其他人 – Avshalom

相關問題