使用远程 PowerShell 连接到 Exchange 服务器Connect to Exchange servers using remote PowerShell

如果您没有在本地计算机上安装 Exchange 管理工具,您可以使用 Windows PowerShell 创建与 Exchange 服务器的远程 PowerShell 会话。它是一个简单的三个步骤过程,其中您输入您的凭据,提供所需的连接设置,然后将 Exchange cmdlet 导入本地 PowerShell 会话,以便您可以使用它们。If you don't have the Exchange management tools installed on your local computer, you can use Windows PowerShell to create a remote PowerShell session to an Exchange server. It's a simple three-step process, where you enter your credentials, provide the required connection settings, and then import the Exchange cmdlets into your local Windows PowerShell session so that you can use them.

Note

我们建议您在您使用大量管理 Exchange 服务器的任何计算机上使用 Exchange 命令行管理程序。通过安装 Exchange 管理工具,您将获取 Exchange 命令行管理程序。有关详细信息,请参阅安装 Exchange Server 管理工具打开 Exchange Management Shell。有关 Exchange 命令行管理程序的详细信息,请参阅Exchange Server PowerShell (Exchange Management Shell)We recommend that you use the Exchange Management Shell on any computer that you use to extensively administer Exchange servers. You'll get the Exchange Management Shell by installing the Exchange management tools. For more information, see Install the Exchange Server Management Tools and Open the Exchange Management Shell. For more information about the Exchange Management Shell, see Exchange Server PowerShell (Exchange Management Shell).

在开始之前,您需要知道什么?What do you need to know before you begin?

  • 估计完成时间:少于 5 分钟Estimated time to complete: less than 5 minutes

  • 可以使用下列 Windows 版本:You can use the following versions of Windows:

    • Windows 10Windows 10

    • Windows 8.1*Windows 8.1*

    • Windows Server 2016Windows Server 2016

    • Windows Server 2012 R2*Windows Server 2012 R2*

    • Windows Server 2012**Windows Server 2012**

    *您需要安装 Microsoft.NET Framework 4.5.2 或更高版本。有关详细信息,请参阅安装.NET Framework* You need to install the Microsoft .NET Framework 4.5.2 or later. For more information, see Installing the .NET Framework.

    **后安装.NET Framework 4.5.2 或更高版本,还需要安装 Windows Management Framework 4.0。有关详细信息,请参阅Windows Management Framework 4.0** After you install the .NET Framework 4.5.2 or later, you also need to install the Windows Management Framework 4.0. For more information, see Windows Management Framework 4.0.

  • Windows PowerShell 需要将配置为运行脚本,并不是默认情况下。当您尝试连接时,您将收到以下错误:Windows PowerShell needs to be configured to run scripts, and by default, it isn't. You'll get the following error when you try to connect:

    Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files.

    若要启用 Windows PowerShell,可以运行签名的脚本,请在提升的 Windows PowerShell 窗口 (通过选择运行以管理员身份打开 Windows PowerShell 窗口) 中运行以下命令:To enable Windows PowerShell to run signed scripts, run the following command in an elevated Windows PowerShell window (a Windows PowerShell window you open by selecting Run as administrator):

    Set-ExecutionPolicy RemoteSigned
    

    只需在计算机上配置一次此设置,无需每次连接时都进行配置。You need to configure this setting only once on your computer, not every time you connect.

Tip

有问题?寻求帮助 Exchange 论坛。访问在Exchange Server论坛。Having problems? Ask for help in the Exchange forums. Visit the forums at Exchange Server.

连接远程 Exchange 服务器Connect to a remote Exchange server

  1. 在本地计算机上打开 Windows PowerShell 并运行以下命令:On your local computer, open Windows PowerShell, and run the following command:

    $UserCredential = Get-Credential
    

    在打开Windows PowerShell 凭据请求对话框中,输入您用户主体名称 (UPN) (例如, chris@contoso.com) 和密码,然后单击确定In the Windows PowerShell Credential Request dialog box that opens, enter your user principal name (UPN) (for example, chris@contoso.com) and password, and then click OK.

  2. 替换<ServerFQDN>与您的 Exchange 服务器的完全限定的域名 (例如, mailbox01.contoso.com) 并运行以下命令:Replace <ServerFQDN> with the fully qualified domain name of your Exchange server (for example, mailbox01.contoso.com) and run the following command:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $UserCredential
    

    注意ConnectionUri_值是http,而不httpsNote: The _ConnectionUri value is http, not https.

  3. 运行以下命令:Run the following command:

    Import-PSSession $Session
    

Note

请务必断开远程 PowerShell 会话何时完成。如果不断开会话的情况下关闭 Windows PowerShell 窗口,您无法使用所有远程 PowerShell 会话可供您,而您需要等待过期的会话。要断开远程 PowerShell 会话,请运行以下命令:Be sure to disconnect the remote PowerShell session when you're finished. If you close the Windows PowerShell window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you'll need to wait for the sessions to expire. To disconnect the remote PowerShell session, run the following command:

Remove-PSSession $Session

您如何知道这有效?How do you know this worked?

后的步骤 3,Exchange cmdlet 是导入本地 PowerShell 会话并跟踪的进度栏。如果未收到任何错误,您将成功连接。快速测试是运行 Exchange cmdlet (例如, Get-mailbox) 和查看结果。After Step 3, the Exchange cmdlets are imported into your local Windows PowerShell session and tracked by a progress bar. If you don't receive any errors, you connected successfully. A quick test is to run an Exchange cmdlet (for example, Get-Mailbox) and review the results.

如果您收到错误,请检查以下要求:If you receive errors, check the following requirements:

  • 常见问题是密码错误。重新运行上述三个步骤,特别注意您在第 1 步中输入的用户名和密码。A common problem is an incorrect password. Run the three steps again, and pay close attention to the user name and password you enter in Step 1.

  • 用于连接到 Exchange 服务器的帐户需要启用远程 PowerShell 访问。有关详细信息,请参阅控制对 Exchange 服务器的远程 PowerShell 访问The account you use to connect to the Exchange server needs to be enabled for remote PowerShell access. For more information, see Control remote PowerShell access to Exchange servers.

  • TCP 端口 80 通信需要在本地计算机和 Exchange 服务器之间打开。很可能打开,但是这是一个要考虑是否您的组织有限制的网络访问策略。TCP port 80 traffic needs to be open between your local computer and the Exchange server. It's probably open, but it's something to consider if your organization has a restrictive network access policy.

See alsoSee also

您在本主题中使用的 cmdlet 是 Windows PowerShell cmdlet。有关这些 cmdlet 的详细信息,请参阅下列主题。The cmdlets that you use in this topic are Windows PowerShell cmdlets. For more information about these cmdlets, see the following topics.