PowerShell 远程调用。网络服务器拒绝访问
PowerShell remote call. Access is denied from webserver
我编写了一个代码,用于从 asp.net 应用程序远程访问 exchange powershell,以使用 vb.net 和 exchange 2016 启用远程邮件
命令 运行 从我的 visual studio 调试成功
但是当我放入 iis 网络服务器时,它给了我
Connecting to remote server "" failed with the following error
message : Access is denied
这是代码
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
我找到了任何遇到同样问题的人的解决方案
- 创建用户作为(收件人管理组)的成员
- 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
它会很好用
我编写了一个代码,用于从 asp.net 应用程序远程访问 exchange powershell,以使用 vb.net 和 exchange 2016 启用远程邮件 命令 运行 从我的 visual studio 调试成功 但是当我放入 iis 网络服务器时,它给了我
Connecting to remote server "" failed with the following error message : Access is denied
这是代码
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
我找到了任何遇到同样问题的人的解决方案
- 创建用户作为(收件人管理组)的成员
- 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
它会很好用