Create Appointments for Multiple Users in Office 365 Exchange Online

Introduction

This script can create appointments for multiple users in Office 365 Exchange Online. This script requires you to add proper permission to the default Calendar folder before creating appointments by default. However, this script also allows you to use Impersonation. Impersonation enables an account on an Exchange server to perform actions by using the permissions that are associated with another account.

Scenario

This script can create appointments for multiple users in Office 365 Exchange Online. Under most circumstances, you can send meeting invitations to achieve this goal. But sometimes Office 365 administrators are asked to create appointments with reminders for different kinds of events. These kinds of events should not send invitations. So they need this script. 

Prerequisite

This script requires Exchange Web Service Managed API 2.0. Please download and install the package from Microsoft Download Center. This script cannot work correctly without this package.

Script

This script contains the following advanced functions:

You can use this script in the following way.

1. Open Windows PowerShell.

2. Run Import-Module cmdlet to import this module file.
Import-Module filepath\scriptname.psm1

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
#Save appointment to the default Calendar folderTry 
{ 
    if ($UseImpersonation) { 
        $impersonationUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId(` 
                               [Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,` 
                                ,$userSMTPAddress) 
        $exService.ImpersonatedUserId = $impersonationUserId$newAppointment.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,` 
                             [Microsoft.Exchange.WebServices.Data.SendInvitationsMode]::SendToNone) 
  
        #Clear ImpersonationUserId$exService.ImpersonatedUserId = $null 
    } else { 
        $folderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId(` 
                   [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,` 
                   $userSMTPAddress) 
        $newAppointment.Save($folderId, [Microsoft.Exchange.WebServices.Data.SendInvitationsMode]::SendToNone) 
    } 
} 
Catch 
{ 
    $PSCmdlet.WriteError($_) 
}

Delegate Access and Impersonation in Office 365 Exchange Online

Delegates are account holders who are authorized to perform actions for a primary account. For example, an administrative assistant can be granted access to an executive's calendar to make appointments on the executive's behalf. You can use Outlook Web App (OWA) or Add-MailboxFolderPermission to add mailbox folder permission for multiple users.

For customers who use Hosted Email Plan and Plan E1, you can use impersonation when creating appointments. Please refer to Working with application impersonation in Exchange Online for the details. After that, please use a proper service account to establish the connection when using Connect-OSCEXOWebService. Then you can use the UseImpersonation parameter when using New-OSCEXOAppointment to create appointments.

New-OSCEXOAppointment Syntax (Parameter Sets)

Because you can create appointments with seven types of recurrence by using New-OSCEXOAppointment, and some parameters are shared in two or more syntax (parameter sets), you may find it’s a bit difficult to choose multiple parameters for one recurrence. So it’s recommended to use Show-Command that is available in Windows PowerShell V3 to get a graphic view of parameter sets. You can download Windows PowerShell V3 from Microsoft Download Center.

Examples

Example 1: How to display help about New-OSCEXOAppointment.
To display help about this function, run this command.
Get-Help New-OSCEXOAppointment -Full
 

Example 2: How to initiate a connection to Office 365 Exchange Online.
To initiate a connection to Office 365 Exchange Online, please run this command. You must run this example before any other step.
Connect-OSCEXOWebService -Credential (Get-Credential admin@domain01.onmicrosoft.com)

Note The Connect-OSCEXOWebService function creates a new variable called exService. This variable is in the global scope of the current Windows PowerShell session. This variable is used by other functions in the script. If you want to use impersonation when creating appointments, please use a proper service account to establish the connection.

Example 3: How to create an appointment in the default Calendar for mailbox user John Doe (johnd).
To create an appointment in the default Calendar for mailbox user John Doe (johnd), please run this command.
New-OSCEXOAppointment -Identity johnd -Subject "Company Event" -Location "Meeting Room" -Body "Company Event"
 

Example 4: How to create an appointment in the default Calendar for mailbox user John Doe (johnd) by using impersonation.
To create an appointment in the default Calendar for mailbox user John Doe (johnd) by using impersonation, please run this command.
New-OSCEXOAppointment -Identity johnd -Subject "Company Event" -Location "Meeting Room" -Body "Company Event" -UseImpersonation

Example 5: How to create an all-day event in the default Calendar folder for the mailbox users John Doe (johnd) and Jane Doe (janed).
To create an all-day event in the default Calendar folder for the mailbox users John Doe (johnd) and Jane Doe (janed), please run this command.
"johnd","janed" | New-OSCEXOAppointment -Subject "Company Holiday" -Body "Company Holiday" -AllDayEvent

Example 6: How to create a recurrence appointment in the default Calendar for mailbox user John Doe (johnd).
To a recurrence appointment in the default Calendar for mailbox user John Doe (johnd), please run this command.
New-OSCEXOAppointment -Identity johnd -Subject "Company Event" -DayOfTheWeek Friday -Interval 2 -RecurrenceRangeEndAfter 2
 

Additional Resources

Technical Resources:
Windows PowerShell Advanced Function
Creating appointments and meetings by using the EWS Managed API
Working with recurring calendar items by using the EWS Managed API

Forum Threads:
http://community.office365.com/en-us/forums/158/p/80633/312803.aspx
http://community.office365.com/en-us/forums/158/p/80441/312811.aspx