Search-Mailbox cmdlet 在 Exchange Online 中使用仅应用程序身份验证的可用性

Search-Mailbox cmdlet availability with app-only authentication in Exchange Online

我正在使用 PowerShell 和以下命令连接到 Exchange Online:

Connect-ExchangeOnline -AppId APP_ID -CertificateFilePath CERTIFICATE_PATH -Organization ORG_NAME

并想使用“搜索邮箱”cmdlet。

docs 说:

By default, Search-Mailbox is available only in the Mailbox Search or Mailbox Import Export roles, and these roles aren't assigned to any role groups.

该应用在 Azure 中分配了 Exchange 管理员角色。

在 Exchange 管理中心,我将 Exchange 管理员添加到启用了邮箱搜索角色的发现管理角色组。

重新连接后,搜索邮箱仍然不可用:

Search-Mailbox: The term 'Search-Mailbox' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

有人可以解释为什么它不起作用以及如何让它起作用吗?

CmdLet 不可用时,需要导入、安装或 运行 在正确的服务器上。 Search-Mailbox 似乎是模块 ExchangePowerShell.

的一部分

我认为您需要在 PowerShell 会话中导入模块:

Import-Module -Name 'ExchangePowerShell'

或运行直接在Exchange服务器上使用CmdLet或使用Connect-ExchangeOnline

在我将“邮箱搜索”角色分配给“组织管理”角色组(Exchange 管理员角色组继承自它)后它起作用了。