Powershell 与 Exchange 2013 powershell 的连接随机工作吗?

Powershell 与 Exchange 2013 powershell 的连接随机工作吗?

我目前正在编写一个脚本,用于连接到我们的邮件服务器并清除邮箱中的特定文件夹,除了连接到服务器之外,一切都运行正常。今天早上我尝试时,它运行正常。但如果我现在尝试,我会得到

        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 ...

当我尝试使用https://mail.mailserver.se/Owa/PowerShell它吐出:

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.

下面是代码的连接部分的一部分。

$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

如果我遗漏了什么或者不清楚的话,请原谅。

答案1

找到解决方案

如果我添加“Enable-PSRemoting -Force”,它就会起作用。似乎 WinRM 没有运行。

答案2

您是否使用具有负载平衡功能的多台服务器?

似乎您正在使用外部 uri 来访问 ps。我还没有使用公共 uri 来访问 ps。从一个服务器重定向到另一个服务器将导致相同的 uri,并且负载平衡器上的粘性会话会再次将您重定向到返回重定向的服务器(这将导致另一个重定向)。

尝试使用内部 uri 访问 shell。这可能会解决这个问题。

相关内容