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 (            
$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

This entry was posted in COM, Networking, Outlook, PowerShell V2. Bookmark the permalink.

9 Responses to Create a calendar item

  1. Jeremiah says:

    Where does the “get-mailfolders” command come from? Are you importing a module to get access to it? I get the following error ” The term ‘get-mailfolders’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.”.

  2. Pingback: PowerShell add Holidays to Outlook Calendar | SharePointed

  3. stibinator says:

    This is great! I’ve managed to get my daughter’s entire soccer season into my calendar – by turning the fixtures pdf the coach mailed to me into a csv file and then parsing the individual entries and using your script to create the events.

    Just a couple of hours scripting have saved me possibly ten minute’s worth of manual data entry! 😉

  4. Hello Richard,
    is there any way to add an hyperlink with “join online meeting” in the body of the mail with skype or lync. or so forth ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s