Friday, August 25, 2017

Removing Outlook Calendar Entries for Deleted User

We had a situation where a user left the company, his account was removed from AD/Exchange and many reoccurring and non-important meetings were orphaned on user calendars.  As a result, these entries had to be removed across the organization.  The alternative is for each user to search their calendars, find the invites and deny/delete.  This simply is not feasible and required some scripting!


 $password = "your_pw" | ConvertTo-SecureString -asPlainText -Force  
 $credential = New-Object System.Management.Automation.PSCredential("your_userid",$password)  
 $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection  
 Import-PSSession $session -CommandName Get-Mailbox, Search-MailBox -AllowClobber  
 try  
 {  
   Get-MailBox | Search-Mailbox -SearchQuery 'From:[target_user] and kind:meetings' -TargetMailbox "[target_mailbox]" -TargetFolder "[target_folder]" -DeleteContent  
 }  
 catch  
 {  
   # Do nothing  
 }  
 Remove-PSSession $session  



The target_mailbox is where the data destined to be removed is copied to. The target_folder is a folder name of your selection on the target_mailbox. Before the data is removed from the end users calendar, it is copied to the target_mailbox in the target_folder folder. Generally, this would be your account. When you start the script, you will see this folder show up in Outlook. Should you have to recover anything, you will find it in this account and folder.

No comments:

Post a Comment