0

I am currently working on a script that connects to our mailserver and purges a specific folder in a mailbox, I got everything working without a problem except the connecting to the server. When I tried this morning it worked without an issue. But if i Try now i get

        The WinRM service cannot process the request because the request needs to be sent to a different machine. Use the redirect information to send the request to a new machine.  Redirect location reported: h
    ttps://mail.mailserver.se/owa/PowerShell . To automatically connect to the redirected URI, verify the "MaximumConnectionRedirectionCount" property of the session preference variable "PSSessionOption", and use the "AllowRedirection" p
    arameter on the cmdlet.
    At line:5 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ht ...

When I try to use https://mail.mailserver.se/Owa/PowerShell it spits out:

New-PSSession : [mail.mailserver.se] Connecting to remote server mail.bluestep.se failed with the following error message : WinRM cannot process the request. The following error occurred while using Kerberos
 authentication: The computer mail.bluestep.se is unknown to Kerberos. Verify that the computer exists on the network, that the name provided is spelled correctly, and that the Kerberos configuration for a
ccessing the computer is correct. The most common Kerberos configuration issue is that an SPN with the format HTTP/mail.mailserver.se is not configured for the target. If Kerberos is not required, specify th
e Negotiate authentication mechanism and resubmit the operation. For more information, see the about_Remote_Troubleshooting Help topic.

Here is the part of the connection part of the code.

$password = "MyPasswordHere"
$UserName = "domain\username"
$Credentials = New-Object System.Management.Automation.PSCredential("domain\username", $password)

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Mailserver/PowerShell/ -Authentication Kerberos -Credential $Credentials

    Import-PSSession $Session -AllowClobber

Pardon if i missed something or if this is unclear.

Jakodns
  • 236
  • 1
  • 6
  • 14

2 Answers2

1

Found the solution

If i add "Enable-PSRemoting -Force" it works. Seems like WinRM wasent running.

Jakodns
  • 236
  • 1
  • 6
  • 14
0

are you using multiple servers with loadbalancing?

seems that you're using external uri to access the ps. i didn't use public uri's to access ps yet. a redirection from one to another server would result in the same uri and a sticky session on the load balancer would redirect you again to the server that returned a redirect (which will result in another redirect).

try using internal uri to access the shell. this might solve this issue.

Daniel Nachtrub
  • 1,022
  • 7
  • 12
  • No servers with loadbalancing. I get the same issue using URI – Jakodns Feb 23 '16 at 07:27
  • if you didn't configure windows auth/sso to the webfrontent there is no SPN related to mail.mailserver.de and kerberos won't work. did you setup windows auth/sso? – Daniel Nachtrub Feb 23 '16 at 07:32
  • Pardon my ignorance, since I wasen't the person to set it up, how do i check it? – Jakodns Feb 23 '16 at 16:19
  • Found it, No Windows Auth isent active, but that should give error HTTP 401. Cant find anything about SSO – Jakodns Feb 23 '16 at 16:29
  • Using -AllowRedirection it tells me it connects to https://mail.server.se/owa/powershell Remaning issue now is:"The WinRM client received an HTTP status code of 440 from the remote WS-Management service. For more informat ion, see the about_Remote_Troubleshooting Help topic." – Jakodns Feb 23 '16 at 16:47