keleran
keleran

Reputation: 309

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

I'm connecting to Exchange Online using PowerShell and the following command:

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

And would like to use the "Search-Mailbox" cmdlet.

The docs say:

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.

The app has the Exchange administrator role assigned in Azure.

In Exchange admin center, I added Exchange administrators to the Discovery Management role group that has the Mailbox Search role enabled.

After reconnecting, Search-Mailbox is still not available:

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.

Could someone please explain why it doesn't work and how to make it work?

Upvotes: 1

Views: 6625

Answers (2)

keleran
keleran

Reputation: 309

It worked after I assigned "Mailbox Search" role to the "Organization Management" role group (Exchange administrators role groups inherits from it).

Upvotes: 1

DarkLite1
DarkLite1

Reputation: 14705

When the CmdLet is not available it needs to be imported, installed or run on the correct server. It seems like Search-Mailbox is part of the module ExchangePowerShell.

I believe you either need to import the module in your PowerShell session:

Import-Module -Name 'ExchangePowerShell'

Or run the CmdLet on the Exchange server directly or use Connect-ExchangeOnline.

Upvotes: -2

Related Questions