Page F.P.T
Page F.P.T

Reputation: 671

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

I am currently working on a script that would delete meeting requests from terminated employees of the organization. I found this one as a reference (Deleting Meeting Requests made by terminated users) and i can't get it to work for me because of my error.

this is my script

Add-Type -Path "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.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 [email protected] -TargetFolder "SearchData" -logonly -loglevel full
        #-targetmailbox [email protected] -targetfolder "Deleting Meeting" -deletecontent -force

    }
}

i am connected to Exchange Online so im not sure why Search-Mailbox is not being imported. my account has an Owner permission as well.

Upvotes: 0

Views: 13169

Answers (1)

Ranadip Dutta
Ranadip Dutta

Reputation: 9133

It seems like you do not have the cmdlet available. So check the proper version.

Please do the following and see:

Create "Mailbox Import-Export Management" role group and be a member of it.

To create the role group use:

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

To add the member:
Add-RoleGroupMember "Mailbox Import-Export Management" -Member

Apart from that if you want to search then you can use like this:

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

Hope it helps.

Upvotes: 1

Related Questions