Powershell Script - Upload Appointments to Outlook Group Calendar

Viewed 910

I'm currently working at a Powershell script to pull data from a CSV of a couple thousand appointments that need to be migrated to an Outlook group calendar. As of now, I've been able to parse the data into Outlook events and successfully upload to my personal calendar.

However, I've been unsuccessful uploading to a group calendar. Any suggestions on how I can modify the folder path in my code (see below), to change the save destination from my personal default calendar to a group Calendar which I am the owner of? (E.g. I have a group called "Test-Group" which I am using to test this, it is a calendar I can select and post to in Outlook). Also, I need the O365 group itself to be the owner of the events.

    #Currently handles subject, start date, end date, duration, all day event, body, required attendees, location (room)

    Add-Type -AssemblyName 'Microsoft.Office.Interop.Outlook'

    $outlook = New-Object -ComObject Outlook.Application            
    $namespace = $outlook.GetNameSpace('MAPI')          
    $Calendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar

    # vv folder path for the calendar we are uploading to
    $folder = $namespace.getDefaultFolder($Calendar)

    $ImportFile ="C:\Users\evanv\Downloads\Appointment-Outlook-Test.csv"
    $calendar = $outlook.Session.GetFolderFromID($folder.EntryID, $folder.StoreID)
    $csv = Import-CSV $ImportFile           

    foreach($row in $csv) 
    {       
       $appt = $calendar.Items.Add(1)
       $appt.Subject = $row.Subject
       $appt.Start = $row.StartDate
       #$appt.End = $row.EndDate
       $appt.Duration = $row.Duration
       $appt.AllDayEvent = $false
       $appt.Body = $row.ApptID
       #$appt.Organizer = $row.Clinic  --read only property :(
       $appt.RequiredAttendees = $row.Attendees
       $appt.Location = $row.Room   
       $appt.Body = $row.Location_Street + "\n" + $row.ApptID

       Write-Host "Row " $row.Subject " added to calendar" -ForegroundColor green           
       $appt.Save()             
    }

For the record, I have scoured Google and been unsuccessful thus far in finding anything that fits my needs; an actual solution here would be a welcome surprise.. That said, any other ideas for how to get these events to my group calendar would also be gratefully welcomed!

0 Answers
Related