Get ALL events + recurring events from SharePoint online with PowerShell (Or other script)

1.3k views Asked by At

The bottom line - need to export calendar events to excel/csv file.

Looking to get ALL events from an online SharePoint calendar. I tried using PowerShell script, but the recurring events are not returned. Script -> https://www.sharepointdiary.com/2016/03/export-list-items-to-csv-in-sharepoint-online-using-powershell.html

Tried using the ViewXml part of the query, but not much luck with that.

Any ideas?

Cheers!

1

There are 1 answers

1
Kally_MSFT On

A demo code for your reference:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

##Variables for Processing
$SiteUrl = "https://xxx.sharepoint.com/sites/xxx"
$ListName="cal1"
$ExportFile ="C:\Test\ListRpt.csv"
$UserName="[email protected]"
$Password ="Password"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials

#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)

#Get All List Items
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$ListItems = $List.GetItems($Query)
$context.Load($ListItems)
$context.ExecuteQuery()

#Array to Hold List Items
$ListItemCollection = @()

#Fetch each list item value to export to excel
 $ListItems |  foreach {
    $ExportItem = New-Object PSObject
    $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "StartTime" -value $_["EventDate"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "EndTime" -value $_["EndDate"]

    #Add the object with above properties to the Array
    $ListItemCollection += $ExportItem
 }
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $ExportFile -NoTypeInformation

Write-host "List data Exported to CSV file successfully!"

Result is:
enter image description here