Categories

Create a calendar item

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

function new-calendaritem {            
param (            
            
 [string]$mailbox,            
             
 [datetime]$start,            
             
 [datetime]$end,            
             
 [string]$subject,            
             
 [string]$location,            
             
 [string]$body            
            
)            
$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             
             
$entry.Save()            
            
}


 



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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>