I am trying to create and appointment in Outlook 2007, using PowerShell and I would like to also copy this appointment to my team's shared calendar.
$outlook = new-object -comobject outlook.application
$calendar = $outlook.Session.folders.Item("myemail@aol.com")
$appt = $calendar.Items.Add(1) # == olAppointmentItem
$appt.Start = [datetime]"10/31/2012 17:00"
$appt.End = [datetime]"10/31/2012 18:00"
$appt.Subject = "TEST - Testing the Calender"
$appt.Location = "TEST"
$appt.Body = "Ignore This. I am testing the calendar"
$appt.Categories = "TEST-Category"
$appt.RequiredAttendees = 'myteamate1@aol.com;myteamate2@aol.com'
$appt.OptionalAttendees = 'mymanager@aol.com'
$appt.ReminderSet = $true
$appt.ReminderMinutesBeforeStart = 120
$appt.BusyStatus = 0 # == The user is available; 2=Busy; 3=OOO; 1=Tentative
$appt.Save()
This part works well in that it creates an appointment in my calendar for me.
I would like to copy it to my Team Shared Calendar.
I tried using $appt.CopyTo() and $appt.Move() to no avail.
I do not know what parameters to pass to it. According to Get-Member:
CopyTo Method _AppointmentItem CopyTo (MAPIFolder, OlAppointmentCopyOptions)
Move Method IDispatch Move (MAPIFolder)
When I CopyTo with just the 'MAPIFolder' (and I am pretty sure even this part is wrong), I get:
Cannot find an overload for "CopyTo" and the argument count: "1".
At line:1 char:13
+ $appt.CopyTo <<<< ($b)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
When I add a numeric value for the OlAppointmentCopyOptions (anything), I get no error, but I also do not see anything happening.
I got my MAPIFolder by doing the following:
$calendardest = $outlook.Session.folders.Item("Public Folders - myemail@aol.com")
$calff = $calendardest.Folders
foreach($c in $calff) {
$a=$c.Name
if($c.Name -eq 'Favorites') {
$b=$c.Folders
}
}
$appt.CopyTo($b,0)
Any help on this will be appreciated.