当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell ISE 中的加载 Exchange Management Shell

作者:精品下载站 日期:2024-12-14 18:25:06 浏览:15 分类:玩电脑

PowerShell ISE 中的加载 Exchange Management Shell


在Exchange Server中,我们可以在Windows PowerShell ISE中加载Exchange Management Shell模块。这样,我们就可以在 PowerShell ISE 中运行 Exchange cmdlet,就像我们习惯在 Exchange Management Shell 中一样。但是,还有其他方法可以使用 PowerShell 连接到 Exchange Server 吗?本文将教您如何在 PowerShell ISE 中加载 Exchange Management Shell 管理单元。

信息

Microsoft PowerShell ISE 代表集成脚本环境。如果要运行脚本或 cmdlet,为什么我们喜欢使用 Windows PowerShell ISE?

  • 与编辑器一起工作更舒服

  • 在您键入时显示 cmdlet

  • 更好的界面(GUI)

在 PowerShell ISE 中运行 Exchange cmdlet 时出错

如果您在 PowerShell ISE 中运行 Exchange cmdlet,您将收到错误。

PS C:\> Get-Mailbox
Get-Mailbox : The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Mailbox
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

您确实收到此错误,因为您没有在 Windows PowerShell ISE 中导入 Exchange 管理模块。

在 PowerShell ISE 中导入 Exchange 管理模块

我们想要在 Exchange 服务器上的 PowerShell ISE 中导入 Exchange 模块。我们还希望在另一台安装了 Exchange 管理工具的服务器上执行相同的操作。

要在 PowerShell ISE 中加载 Exchange 管理单元,您可以运行以下 cmdlet。运行 Get-Mailbox cmdlet 以验证其是否正常工作。

添加 Exchange 管理管理单元 Exchange 2010

以管理员身份运行 PowerShell ISE。添加 Microsoft Exchange 管理管理单元。

PS C:\> Add-PSsnapin Microsoft.Exchange.Management.PowerShell.E2010

添加 Exchange 管理管理单元 Exchange 2013/2016/2019

PS C:\> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

PS C:\> Get-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                Ali.Tajran           ex01-2016        Unlimited
Amanda Morgan             Amanda.Morgan        ex01-2016        Unlimited

未安装 Exchange 管理工具

我们有一个管理服务器,我们希望使用 PowerShell ISE 连接到 Exchange Server。如果您在未安装 Exchange 管理工具的另一台服务器上打开它,它将无法工作。

PS C:\> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.
At line:1 char:1
+ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Excha...werShell.SnapIn:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

您收到错误是因为您必须安装 Exchange 管理工具。之后,运行管理单元 cmdlet 以导入 Exchange 管理工具。

使用远程 PowerShell 连接到 Exchange 服务器

上述 Exchange 管理单元 cmdlet 可以正常工作。还有其他方法可以在 PowerShell 中加载 Exchange 模块吗? 是的,有。

通过三个步骤,我们可以创建到 Exchange Server 的远程 PowerShell 连接:

  1. 输入凭据

  2. 提供所需的连接设置

  3. 导入 Exchange cmdlet

您可以从 Exchange Server 本身或其他服务器进行连接。例如,管理服务器。好处是您无需在远程服务器上安装 Exchange Management Shell 即可运行此程序。但是,某些 cmdlet 不会为您提供正确的输出。例如,Get-ExchangeCertificate cmdlet 不会为您提供所有属性。

我们建议在任何服务器上安装 Exchange 管理工具来管理 Exchange 服务器。

以管理员身份运行 PowerShell ISE 并运行 Get-ExecutionPolicy cmdlet 以检查其设置是否正确。如果未设置为 RemoteSigned,请运行第二个 cmdlet。

PS C:\> Get-ExecutionPolicy

PS C:\> Set-ExecutionPolicy RemoteSigned

1. 输入凭据

PS C:\> $UserCredential = Get-Credential

将显示提示。填写具有管理员权限的帐户UPN。

[玩转系统] PowerShell ISE 中的加载 Exchange Management Shell

2. 提供所需的连接设置

EX01-2016.exoip.local 替换为您的 Exchange 服务器 FQDN。 ConnectionUri 是 http 而不是 https。

PS C:\> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EX01-2016.exoip.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential

3. 导入 Exchange cmdlet

在 Windows PowerShell 会话中导入 Exchange cmdlet,以便您可以管理 Exchange。

PS C:\> Import-PSSession $Session -DisableNameChecking

如果连接到 PowerShell 虚拟目录时出现错误,请阅读在 Exchange Server 中重新创建虚拟目录。

验证它是否正常工作

运行 Get-Mailbox cmdlet 并查看结果。

PS C:\> Get-Mailbox

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                Ali.Tajran           ex01-2016        Unlimited
Amanda Morgan             Amanda.Morgan        ex01-2016        Unlimited

如果您完成了工作,请不要忘记签字。

PS C:\> Remove-PSSession $Session

您确实从另一台服务器或从 Exchange 服务器本身连接到 Exchange Server。这次使用远程 PowerShell。这是否为您在 PowerShell ISE 中加载了 Exchange cmdlet?

继续阅读:安装 Exchange Online PowerShell 模块 »

结论

在本文中,您了解了如何在 PowerShell ISE 中加载 Exchange Management Shell。下次连接到 Exchange Server 时,您可以使用远程 PowerShell 连接而不加载 Exchange 管理单元。两种方法都会起作用。

最好在任何服务器上安装 Exchange 管理工具来管理 Exchange 服务器。之后,在 PowerShell ISE 中导入 Exchange 管理单元。这样,所有 Exchange cmdlet 都可用。

您喜欢这篇文章吗?您可能还喜欢安装 Exchange 累积更新。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯