header image

Create a calendar item

Posted by: | September 12, 2011 | No Comment |

Continuing the occasional look at Outlook automation its time to see how we create a calendar item

function new-calendaritem {            
param (            
$outlook = New-Object -ComObject Outlook.Application            
$folder = get-mailfolders |             
where {$_.Path -like "*calendar*" -and $_.Path -notlike "*birthday*" -and $_.Path -like "*$mailbox*"}            
$calendar = $outlook.Session.GetFolderFromID($folder.EntryID, $folder.StoreID)            
$entry = $calendar.Items.Add(1)            
$entry.Start = $start            
$entry.End = $end            
$entry.Subject = $subject            
$entry.Location = $location            
$entry.Body = $body             


The appropriate calendar is identified – remember I have 4 to choose from. The Add method is used from the calendar items collection and the properties populated.

I always enter dates like this “14 September 2011 11:00” as it removes any problems with culture. In the UK this would be “14/9/2011 11:00” but when entering in this style I have to remember to use the US format “9/14/2011 11:00”

The mailbox parameter helps identify which calendar the entry goes

under: COM, Office 2010, Outlook, PowerShellV2