Skip to main content

Update mailbox data via PowerShell

This documentation contains code blocks in PowerShell to get better acquainted with the Outlook API and describes how data can be modified or written.

Use case

This interface can be handy when calendar items or task folders need to be moved to other folders or when items with certain conditions need to be renamed accordingly.

Update task property

 

Update calendar entry property 

With this PowerShell script you can append a string to each entry in an Outlook calendar. This PowerShell code can be modified to append or rename certain entries based on conditions. This code block is only there to help you understand how to write calendar data using the Outlook API.

$UPN = "<upnofmailboxuser>"
$Calendarname = "<calendarname>"
$ol = New-Object -comobject Outlook.Application
$ns = $ol.GetNamespace('MAPI')
$Folder = $ns.Folders.Item("$UPN").Folders.Item('Calendar').Folders.Item($Calendarname)
$AllCalendarItems = $folder.Items
foreach($Item in $ALlCalendarItems){
	$Item.Subject = $Item.Subject+ "<addedstring>"
	$Item.Save()
}

On the variable $Item you can modify much more than just the property "subject" as described in this code snippet. The object $Item has the following properties, some of them are read only:

Application                   : Microsoft.Office.Interop.Outlook.ApplicationClass
Class                         : 26
Session                       : Microsoft.Office.Interop.Outlook.NameSpaceClass
Parent                        : System.__ComObject
Actions                       : System.__ComObject
Attachments                   : System.__ComObject
BillingInformation            :
Body                          :
Categories                    :
Companies                     :
ConversationIndex             : 01D7B5EF7B35E7MEID40851A74372A7528A4DBD0B01D4
ConversationTopic             : <calendarentrysubject>
CreationTime                  : 30.09.2021 13:37:02
EntryID                       : 00000000BDDCD184419E744399016488F52BF3350700709714C02317F5438DBD0748BFEB3A0C00000000010D0000709714C02317F5438DBD0748BFEB3A0C00025A3F31BB0000
FormDescription               : System.__ComObject
GetInspector                  : System.__ComObject
Importance                    : 1
LastModificationTime          : 20.10.2022 07:53:55
MAPIOBJECT                    : System.__ComObject
MessageClass                  : IPM.Appointment
Mileage                       :
NoAging                       : False
OutlookInternalVersion        : 1615629
OutlookVersion                : 16.0
Saved                         : True
Sensitivity                   : 0
Size                          : 6644
Subject                       : <calendarentrysubject>
UnRead                        : False
UserProperties                : System.__ComObject
AllDayEvent                   : False
BusyStatus                    : 2
Duration                      : 15
End                           : 30.09.2021 13:45:00
IsOnlineMeeting               : False
IsRecurring                   : False
Location                      :
MeetingStatus                 : 0
NetMeetingAutoStart           : False
NetMeetingOrganizerAlias      :
NetMeetingServer              :
NetMeetingType                : 0
OptionalAttendees             :
Organizer                     : <calendarentryorganizer>
Recipients                    : System.__ComObject
RecurrenceState               : 0
ReminderMinutesBeforeStart    : 5
ReminderOverrideDefault       : False
ReminderPlaySound             : False
ReminderSet                   : False
ReminderSoundFile             :
ReplyTime                     : 01.01.4501 00:00:00
RequiredAttendees             : <calendarentryrequiredattendees>
Resources                     :
ResponseRequested             : True
ResponseStatus                : 0
Start                         : 30.09.2021 13:30:00
NetMeetingDocPathName         :
NetShowURL                    :
Links                         :
ConferenceServerAllowExternal : False
ConferenceServerPassword      :
ItemProperties                : System.__ComObject
EndTimeZone                   : System.__ComObject
ConversationID                : E7MEID40851A74372A7528A4DBD0B01D4
RTFBody                       : {123, 92, 114, 116...}
BodyFormat                    : 2
DoNotForwardMeeting           : False
FOthersAppt                   : False
FDelegateAppt                 : False
OnlineMeetingProvider         : 5
DefaultOnlineMeetingEnabled   : False