术语 'Search-Mailbox' 未被识别为 cmdlet Exchange Online Powershell 的名称

The term 'Search-Mailbox' is not recognized as the name of a cmdlet Exchange Online Powershell

我目前正在编写一个脚本,用于删除组织中已离职员工的会议请求。我找到这个作为参考 (Deleting Meeting Requests made by terminated users),但由于我的错误,我无法让它为我工作。

这是我的脚本

Add-Type -Path "C:\Program Files (x86)\Microsoft\Exchange\Web Services.1\Microsoft.Exchange.WebServices.dll"


$UserCredential = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $session -AllowClobber
#Enter-PSSession $session

$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited  

$count=$rooms.count
$TerminatedUsers = Get-Content D:\Work\SHAR78\resignedEmployees.txt

Write-Host "count of rooms " $count

foreach ($user in $TerminatedUsers) {

   Write-Host "terminated user" $user

    foreach($room in $rooms) {

        $room | Search-Mailbox -searchquery "kind:calendar from:$($user)" -targetmailbox admin@admin.com -TargetFolder "SearchData" -logonly -loglevel full
        #-targetmailbox administrator@domain.com -targetfolder "Deleting Meeting" -deletecontent -force

    }
}

我已连接到 Exchange Online,所以我不确定为什么 Search-Mailbox 没有被导入。我的帐户也有所有者权限。

您似乎没有可用的 cmdlet。所以检查正确的版本。

请执行以下操作并查看:

创建“邮箱导入导出管理”角色组并成为其成员。

要创建角色组,请使用:

New-RoleGroup "Mailbox Import-Export Management" -Roles "Mailbox Import Export"

添加成员:
Add-RoleGroupMember "Mailbox Import-Export Management" -Member

除此之外,如果你想搜索,你可以这样使用:

Get-mailbox | Export-Mailbox –AllContentKeywords "thekeysyouwant" –TargetMailbox Administrator –TargetFolder 'foldername'

希望对您有所帮助。