How to free up the conference room calendar from terminated employees’ meetings? Here are the base line PowerShell commands for you to write a script.
To check if any meetings booked by employees in any of the conference rooms who no longer works in your office:
Get-Mailbox -RecipientTypeDetails RoomMailbox | Search-Mailbox -Searchquery "kind:meetings from:<DisplayName>" -EstimateResultOnly | Select Identity,ResultItemsCount | ft -AutoSize
Note: Replace <DisplayName> in the command above with terminated user’s display name.
To Delete the meetings booked by the terminated employees:
Get-Mailbox -RecipientTypeDetails RoomMailbox | Search-Mailbox -Searchquery "kind:meetings from:<DisplayName>" -DeleteContent -Force
Now the script to purge all meeting booked by terminated users.
Note: Change the SEARCHBASE options according to your AD environment. If you remove -SEARCHBASE option from Search-ADAccount command in the script, it will list all disabled accounts from entire domain.
<# * * * * * Purge Meetings Booked by Terminated Users * * * * * Delete meetings from conference rooms booked by employees terminated last 7 days. Written by: Anand, the Awesome Created on: 12/21/2018 #> $dt = date_time $logfile = ".\PurgeMeetings-of-termed-users" + $dt + ".log" Start-Transcript -Path $logfile #Get the terminiated user list <# Note: Important REPLACE THE SEARCH BASE - BASED ON YOUR AD ENVIRONMENT HERE BELOW #> $TermedUsers = Search-ADAccount -AccountDisabled -SearchBase 'OU=Users,DC=corp,DC=company,DC=com' #List all conference rooms $ConferenceRooms = Get-Mailbox -RecipientTypeDetails RoomMailbox foreach($TermedUser in $TermedUsers) { Write-Host "Processing $($Termeduser.Name).." #Delete tehe meeting booked by terminated user $ConferenceRooms | Search-Mailbox -Searchquery "kind:meetings from:$($TermedUser.Name)" -DeleteContent -Confirm:$false -Force } Stop-Transcript # * * * End of the Script * * *