2017-05-24 226 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

相关问题