J'écris un code pour l'accès à distance pour l'échange PowerShell de l'application asp.net pour permettre le courrier distant en utilisant vb.net et échangez 2016 la commande lancée avec succès à partir de mon déboguage Visual Studio mais quand je mets en iis serveur web, il me donneAppel distant PowerShell. L'accès est refusé à partir du serveur web
Connexion au serveur distant "" a échoué avec l'erreur suivante message: l'accès est refusé
c'est est le code
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
probablement un problème d'autorisations: https://support.microsoft.com/fr-us/help/2905767/-access-is-denied-error-quand-vous-connectez-vous-a-echange-en-ligne-en-utilisant-remote-windows-powershell – N0Alias
Je lance le code sous l'utilisateur PSCredential dans lequel il fonctionne le mode débogage mais dans le serveur Web ne fonctionne pas –
Parfois, les serveurs Web sont verrouillés dans les zones démilitarisées et peuvent ne pas être connectés au domaine, ce qui fait référence à AccountOperator La connexion et AccountOperatorPassword pourraient être le problème. – N0Alias