Photo by Jorge Jesus on Pexels.com

Introduction

In certain scenarios, it becomes necessary to generate holiday or other calendar entries across all user’s Office 365 mailboxes. This used to be a laborious process, typically involving the importation of PST files into each mailbox or utilizing the EWS API.

However, Microsoft has introduced an efficient solution through the Microsoft Graph, simplifying this task considerably. Let’s explore how to accomplish this more effortlessly.

Pre-requisites

Create App Registration

  • Sign in to the Azure portal (https://portal.azure.com) using your credentials.
  • Click on the “Azure Active Directory” service from the left-hand side menu.
  • In the Azure Active Directory pane, select “App registrations” under the “Manage” section.
  • Click on the “New registration” button to create a new app registration.
  • Enter a name like “Create Calendar Entries” for app registration in the “Name” field.
  • Choose first option of Single tenant in “Supported account types”.
  • Keep the “Redirect URI” section blank.
  • Click on the “Register” button to create the app registration.
  • Once the registration is complete, Navigate to “API permissions” under the “Manage” section.
  • Click on the “+ Add a permission” button to grant permissions.
  • In the “Request API permissions” pane, select the “Microsoft Graph” API.
  • Choose the appropriate permission scope(s) for Calendars.ReadWrite access.
  • In the API permissions pane, click on the “Grant admin consent” button to grant the permissions to your organization and screen should look like this.

Create Self Signed Certificate for Authentication

  • Run this command on the machine about to be used to run the command, This certificate has to be uploaded the application created above :
$Certificate= New-SelfSignedCertificate –Subject calndar.learntechfuture.com -CertStoreLocation Cert:\CurrentUser\My

Export-Certificate -Cert $Certificate -FilePath "C:\AppCertificate.cer" 
  • Copy the certificate from AppCertificate.cer

Upload Certificate to Azure App

  • Navigate to Certificates & secrets.
  • Under “Certificates”, upload the certificate and now it should look like this :

Import Microsoft Graph and Create Calendar Entries

First, we’ll import the Microsoft Graph Module, then prepare the calendar details, and finally, proceed to create the calendar entry in a mailbox. You can apply this identical method to perform bulk calendar entry operations across multiple mailboxes.

Connect to Microsoft Graph Powershell

  • Ensure that you connect to the right application ID because that only has the calendar read/write permission. In below, I have used my tenantid, AppID, Certificate Thumbprint. Please change these as per your tenant specific details
Connect-MgGraph -TenantId "83e71158-e9a4-4730-bb3f-62d323b54bf4" -AppId "cb3f1882-618a-45d5-972a-3f89e614c477" -CertificateThumbprint "3353062F6C8982D45DCEC1767364B910050FC504"

Import-Module Microsoft.Graph.Calendar

Prepare the Parameter file to create celandar entry

I’m creating a calendar appointment titled “G20 in Delhi,” with a message body of “Welcome to the G20!” The scheduled time is set for September 9, 2023, from 12:00 PM to 6:00 PM IST.

  • Adjust the text as per your end. and Always test..test..and test.

Refer this page for more parameters’ and options for calendar entry.

$params = @{
subject = "G20 in Delhi"
body = @{
contentType = "HTML"
content = "Welcome to the G20!"
}
start = @{
dateTime = "2023-09-09T12:00:00"
timeZone = "India Standard Time"
}
end = @{
dateTime = "2023-09-09T18:00:00"
timeZone = "India Standard Time"
}
location = @{
displayName = "Hotel Taj Palace, New Delhi"
}
allowNewTimeProposals = $true
}
  • Copy the entire content into PowerShell so that it can be stored within a “params” variable.

Create Calendar entry

  • Run this command and change UserID, if you need to do the same entry for multiple users, you can use forach each loop.
New-MgUserEvent -UserId AlexW@learntechfuture.onmicrosoft.com -BodyParameter $params
  • Validate the Calendar entry

Validate Calendar entry

get-MgUserEvent -UserId AlexW@learntechfuture.onmicrosoft.com

Thank you for reading !