Outlook: removing calendar entries

We recently looked at dumping the Calendar entries

http://msmvps.com/blogs/richardsiddaway/archive/2011/08/23/outlook-viewing-calendar-entries.aspx

 

I usually leave entries to build up in the Calendar but a simple clean operation is to delete everything that occurred before a certain date

function remove-calendaritem {            
param (            
 [datetime]$date            
)            
$outlook = New-Object -ComObject Outlook.Application            
            
get-mailfolders |             
where {$_.Path -like "*calendar*" -and $_.Path -notlike "*birthday*"} |            
foreach {            
  $targetfolder = $outlook.Session.GetFolderFromID($_.EntryID, $_.StoreID)            
              
  $targetfolder.Items | foreach {            
    if ($_.StartTime -lt $date){$_.Delete()}            
  }             
}            
}


The date parameter defines the date for which we want to delete all earlier entries. Get the calendar folders and test the StartTime of each entry. If its before our date then delete it.

One Response to Outlook: removing calendar entries

  • Adam Poole says:

    Hi Richard,

    I am trying to use this script to remove entries in a calendar yet the date filter does not seem to work. Some entries are always left. I have removed the date filter as I am happy for everything to be deleted yet still the function only deletes some entries. Any ideas?

    function remove-calendaritem {

    $outlook = New-Object -ComObject Outlook.Application

    get-mailfolders |
    where {$_.Path -like “*calendar*” -and $_.Path -notlike “*birthday*”} |
    foreach {
    $targetfolder = $outlook.Session.GetFolderFromID($_.EntryID, $_.StoreID)
    $targetfolder.Items | foreach {
    $_.Delete()
    }
    }
    }

    remove-calendaritem

Leave a Reply