Powershell connection to exchange 2013 powershell works randomly?

5,227

Found the solution

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

Share:
5,227

Related videos on Youtube

Jakodns
Author by

Jakodns

Junior IT peerson. Learning powershell.

Updated on September 18, 2022

Comments

  • Jakodns
    Jakodns over 1 year

    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
    Jakodns about 8 years
    No servers with loadbalancing. I get the same issue using URI
  • Daniel Nachtrub
    Daniel Nachtrub about 8 years
    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?
  • Jakodns
    Jakodns about 8 years
    Pardon my ignorance, since I wasen't the person to set it up, how do i check it?
  • Jakodns
    Jakodns about 8 years
    Found it, No Windows Auth isent active, but that should give error HTTP 401. Cant find anything about SSO
  • Jakodns
    Jakodns about 8 years
    Using -AllowRedirection it tells me it connects to 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."