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

[玩转系统] 连接到 Exchange Online PowerShell

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

连接到 Exchange Online PowerShell


安装 Exchange Online PowerShell 模块后,您可以连接到 Exchange Online。连接 Exchange Online PowerShell 后,您可以使用单个命令或脚本执行批量操作等。在本文中,我们将向您展示如何使用 Windows PowerShell 连接到 Exchange Online。

Exchange Online PowerShell 模块

让我们看看计算机上安装了哪个 Exchange Online PowerShell 模块版本以及如何将 Exchange Online PowerShell 模块更新到最新版本。

设置 PowerShell 执行策略

要更改 PowerShell 执行策略,我们必须首先以管理员身份运行 Windows PowerShell。

默认情况下,PowerShell 控制台不允许我们运行脚本。我们可以使用 cmdlet Set-ExecutionPolicy 启用脚本执行。

要设置执行策略,请使用以下 PowerShell cmdlet。

Set-ExecutionPolicy RemoteSigned

您将在屏幕上看到以下结果。按Y,然后按Enter

PS C:\> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y

警告:您必须关闭 PowerShell 窗口并重新打开它才能保存更改并避免错误。

在我们连接到 Exchange Online 之前,您必须安装 Exchange Online PowerShell 模块。

检查 Exchange Online PowerShell 模块版本

您可以检查是否已安装 Exchange Online PowerShell V3 模块并查看正在运行的版本。

在 PowerShell 中使用以下命令来验证您是否已安装 Exchange Online PowerShell。

Get-InstalledModule

现在您将看到所有已安装模块和版本的列表。

PS C:\> Get-InstalledModule

Version        Name                           Repository       Description
-------        ----                           ----------       -----------
3.1.0          ExchangeOnlineManagement       PSGallery        This is a General Availability (GA) release of the Exchange Online Powershell V3 module. Exchange Online cmdlets in this module are REST-backed and…
1.4.8.1        PackageManagement              PSGallery        PackageManagement (a.k.a. OneGet) is a new way to discover and install software packages from around the web….
2.2.5          PowerShellGet                  PSGallery        PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, DSC Resources, Role Cap…

更新 PowerShellGet 模块

您可以始终保持 PowerShell 模块最新并运行以下命令。

Update-Module PowerShellGet

连接到 Exchange Online

以管理员身份打开 Windows PowerShell 并运行以下 cmdlet。

Connect-ExchangeOnline

将打开登录帐户窗口,您可以在其中选择帐户并输入密码。然后点击登录

[玩转系统] 连接到 Exchange Online PowerShell

如果您启用了 MFA,您将收到以短信形式发送或发送到手机上的身份验证应用程序的验证码。如果您的 MFA 被禁用,您将无法在此处执行任何操作。

现在您必须返回 PowerShell 窗口。

就是这样!您已成功连接到 Exchange Online。

验证 PowerShell 连接

要验证您是否已连接到 Exchange Online,可以使用 Get-EXOMailbox cmdlet 进行检查。

以管理员身份打开 PowerShell 并使用以下 cmdlet。

Get-EXOMailbox | ft UserPrincipalName,DisplayName

它将显示 Microsoft 365 中所有邮箱的列表。

PS C:\> Get-EXOMailbox | ft UserPrincipalName,DisplayName

UserPrincipalName          DisplayName
-----------------          -----------
[email protected]       Zoë Howard
[email protected]    Amanda Morgan
[email protected]      Amelia Nash
[email protected]   Stephen Hunter
[email protected]      Carol Baker
[email protected]     Craig Hansen
[email protected]       Curt Berry

断开 Exchange Online

完成会话后,您必须断开与远程 PowerShell 的连接。使用 Exchange Online 时,它会清除所有活动会话。

使用以下 cmdlet 断开与 Exchange Online PowerShell 的连接。

Disconnect-ExchangeOnline

您将收到下面的通知文本。要确认,请按 Y ,然后按 Enter

PS C:\> Disconnect-ExchangeOnline

Running this cmdlet clears all active sessions created using Connect-ExchangeOnline or Connect-IPPSSession.
Press(Y/y/A/a) if you want to continue.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y

或者使用以下 cmdlet 断开与 Exchange Online PowerShell 的连接,无需确认文本。

Disconnect-ExchangeOnline -Confirm:$false

常见问题 (FAQ)

如何以管理员身份运行 Exchange Online PowerShell?

单击“开始”并搜索 PowerShell 应用。在右侧,您应该单击以管理员身份运行。或者,您可以右键单击 PowerShell 图标并选择以管理员身份运行。这样,您就可以不受限制地运行 PowerShell 命令。

我需要安装哪个 Exchange Online PowerShell 模块?

最好安装最新的 EXO V3 模块,因为它支持 Windows、Linux 和 MacOS 上的 PowerShell 7。它还使用现代身份验证和 MFA,更加安全。如果您使用的是较旧的 PowerShell 模块 (EXO V2),可以将其更新到最新的 PowerShell 模块。

了解更多:安装 Exchange Online PowerShell »

连接到 Exchange Online PowerShell 时是否需要多重身份验证 (MFA)?

要连接到 Exchange Online PowerShell,您不需要启用 MFA。 cmdlet Connect-ExchangeOnline 适用于具有或不具有 MFA 的帐户。但是,我们建议启用 MFA 以保护您的组织并具有强大的安全性。

阅读更多:提高和改进 Azure MFA 安全性 »

如何在没有登录提示的情况下连接到 Exchange Online Powershell(无人值守脚本)?

您可以连接到 Exchange Online PowerShell,而无需插入用户凭据或获取 MFA 提示。要在 Exchange Online PowerShell 中运行无人值守的自动化脚本,您必须配置基于证书的身份验证 (CBA)。

了解更多:配置基于证书的身份验证以运行自动化 PowerShell 脚本 »

结论

您已成功连接到 Exchange Online Powershell。在连接 Exchange Online 之前,必须安装 Exchange Online PowerShell 模块。我们建议您检查您拥有的模块版本并将其更新到最新版本。最后,请记住在完成后断开 Exchange Online。

您喜欢这篇文章吗?您可能还喜欢使用 PowerShell 批量创建共享邮箱。不要忘记关注我们并分享这篇文章。

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

取消回复欢迎 发表评论:

关灯