Forum Discussion
MKMVMN
May 15, 2024Copper Contributor
Add a calendar ics with Powershell
Hello I need to add a shared calendar (ics) for around thirty people The calendar is from a company A, shared with company B. I want to add this calendar (.ics) automatically for all user...
LeonPavesic
May 15, 2024Silver Contributor
Hi MKMVMN,
you can try to download the .ics file and then add it tu multiple users with this script:
# Install the Exchange Online module if not already installed
Install-Module -Name ExchangeOnlineManagement
# Import the necessary modules
Import-Module ExchangeOnlineManagement
# connect to Exchange Online
Connect-ExchangeOnline
# Path to the .ics file
$icsFilePath = "C:\path\to\shared_calendar.ics"
# List of user email addresses
$userEmails = @(
"email address removed for privacy reasons",
"email address removed for privacy reasons",
"email address removed for privacy reasons"
)
# Loop through each user and add the .ics calendar
foreach ($userEmail in $userEmails) {
try {
# Access the user's mailbox
$mailbox = Get-Mailbox -Identity $userEmail
if ($mailbox) {
# Load the .ics file
$icsContent = Get-Content -Path $icsFilePath -Raw
# Add the .ics calendar to the user's mailbox
Add-MailboxCalendarFolder -Identity $mailbox -Name "Shared Calendar" -Calendar $icsContent
Write-Output "Successfully added calendar to $userEmail"
} else {
Write-Output "Mailbox not found for $userEmail"
}
} catch {
Write-Output "Error adding calendar to $userEmail: $_"
}
}
# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false
- Ensure the path to the .ics file is correct.
- Make sure you have the necessary permissions to access and modify the users' calendars.
MKMVMN
May 16, 2024Copper Contributor
Hello LeonPavesic
Thank for your help,
I have this error message :
PS C:\Windows\system32> C:\test\script.ps1
----------------------------------------------------------------------------------------
This V3 EXO PowerShell module contains new REST API backed Exchange Online cmdlets which doesn't require WinRM for Client-Server communication. You can now run these cmdlets after turning off WinRM Basic Auth in
your client machine thus making it more secure.
Unlike the EXO* prefixed cmdlets, the cmdlets in this module support full functional parity with the RPS (V1) cmdlets.
V3 cmdlets in the downloaded module are resilient to transient failures, handling retries and throttling errors inherently.
REST backed EOP and SCC cmdlets are also available in the V3 module. Similar to EXO, the cmdlets can be run without WinRM basic auth enabled.
For more information check https://aka.ms/exov3-module
----------------------------------------------------------------------------------------
Error adding calendar to xx@xx : The term 'Add-MailboxCalendarFolder' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.