Generate Demo Events for SharePoint Events List
This sample script generates demo events for the SharePoint Events List within a modern site using a CSV file
Summary
This sample script generates demo events for the SharePoint Events List within a modern site. This uses a CSV to load sample events that includes, titles, descriptions, start, end times, category. The script will use the current date and add days to the events from the CSV file to create example events in the future relative to the current date.
This scenario shows how to bulk add events and could be modified to bulk load events into the SharePoint Events List.

Connect-PnPOnline https://contoso.sharepoint.com/sites/demo -Interactive
# Load Data from CSV File
$eventsToAdd = Import-CSV events.csv
# Each time you run the script it will use the current date and set it X number of days in the future.
$eventsToAdd | ForEach-Object {
# Uses todays date as the date
# Date format is Month/Day/Year Hour/Minute
$format = "MM/dd/yyyy HH:mm"
# Add Days
$today = ((Get-Date).AddDays($_.FutureDays)).ToString("MM/dd/yyyy")
$startDateTime = $today + " $($_.StartTime)"
$endDateTime = $today + " $($_.EndTime)"
Write-Host "Adding $startDateTime StartDate"
Write-Host "Adding $endDateTime EndDate"
$values = @{
"Title" = $_.Title;
"Category" = $_.Category;
"Description" = $_.Description;
"fAllDayEvent" = $_.AllDayEvent;
"Location" = $_.Location;
"EventDate" = $startDateTime;
"EndDate" = $endDateTime;
}
Add-PnPListItem -List "Events" -ContentType "Event" -Values $values
}
# Ensure connected to tenant
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
m365 login
}
# Site to which we will add the events
$site = "https://example.sharepoint.com/sites/testEventsScript"
# Load Data from CSV File
$eventsToAdd = Import-CSV events.csv
# Each time you run the script it will use the current date and set it X number of days in the future.
$eventsToAdd | ForEach-Object {
# Uses todays date as the date
# Date format is Month/Day/Year Hour/Minute
$format = "MM/dd/yyyy HH:mm"
# Add Days
$today = ((Get-Date).AddDays($_.FutureDays)).ToString("MM/dd/yyyy")
$startDateTime = $today + " $($_.StartTime)"
$endDateTime = $today + " $($_.EndTime)"
Write-Host "Adding $startDateTime StartDate"
Write-Host "Adding $endDateTime EndDate"
m365 spo listitem add --contentType "Event" --listTitle "Events" --webUrl $site --Title $_.Title --Category $_.Category --Description $_.Description --fAllDayEvent $_.AllDayEvent --Location $_.Location --EventDate $startDateTime --EndDate $endDateTime
}
Title,FutureDays,StartTime,EndTime,Description,Category,AllDayEvent,Location
All Company Away Day,10,10:00,11:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"Bath, England"
Senior Management Quarterly Announcements,90,12:00,13:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"Bath, England"
Senior Management Quarterly Announcements,180,10:00,11:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"Bristol, England"
Company Internal Conference,35,09:00,17:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"Cardiff, Wales"
Training Event: Office 365,15,10:00,11:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"London, England"
Training Event: Security,20,12:00,13:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"London, England"
Training Event: Using Teams,25,12:00,13:00,This is a corporate event for everyone to join,Corporate Event,FALSE,"London, England"
Contributors
| Author(s) |
|---|
| Paul Bullock |
| Adam Wójcik |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
Tool documentation & references
- Want to learn more about PnP PowerShell and the cmdlets
Check out the PnP PowerShell site to get started and for the reference to the cmdlets.
- Want to learn more about CLI for Microsoft 365 and the commands
Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.