Wednesday, 15 February 2012

powershell - Save changes to a mailitem's inspector -



powershell - Save changes to a mailitem's inspector -

i writing script in powershell 2.0 create bunch of appointments on calendar using outlook com object. had code working, end user requested adding formatted tables body of appointments. after trying several other options ended using mailitem.getinspector.wordeditor edit body. unable body saved without having open item in outlook , hitting save. here relevant code:

$newcalenderitem = $folder.items.add() $newcalenderitem.subject = $appt.subject $newcalenderitem.location = $location $newcalenderitem.start = $d.addhours($timeslot.time) $newcalenderitem.duration = 60 * $timeslot.duration $newcalenderitem.busystatus = 2 $newcalenderitem.reminderset = $false $newcalenderitem.categories = $appt.category $newcalenderitem.body = "" if ($appt.bodyfile) { $newcalenderitem.getinspector.wordeditor.range().insertfile("c:\body.rtf", "", $false, $false, $false) #this doesn't save $newcalenderitem.getinspector.wordeditor.close([ref] -1) } #this saves body $newcalenderitem.save()

i have tried getinspector.close(), wordeditor.close(), , wordeditor.save() brings save dialog. know how accomplish this?

you need set appointmentitem.rtfbody property - outlook appointments, tasks, , contacts work rtf rather html. can read rtf file variant array of byte pass rtfbody property.

powershell com outlook powershell-v2.0

No comments:

Post a Comment