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 admin@admin.com -TargetFolder "SearchData" -logonly -loglevel full
#-targetmailbox administrator@domain.com -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.