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
可能是一個權限問題:https://support.microsoft.com/en-us/help/2905767/-access-is-denied-error-when-you-connect-to-exchange-online-by-using-remote-windows-powershell – N0Alias
我在用戶PSCredential下運行代碼調試模式,但在Web服務器不工作 –
有時Web服務器被鎖定在DMZ中,可能沒有連接到域,所以引用AccountOperator登錄 和AccountOperatorPassword可能是問題。 – N0Alias