0

* EDIT: *

Managed to fetch the reccuring events. How do I overcome the year limit?

        <Value Type='DateTime'>
           <Year/>
        </Value>

I want to get all items, even 5 years ahead.

-------- Original ----------

I am trying to run a PowerShell script to export all events from a SharePoint-2010 calendar including recurring events. I got references from

https://github.com/CompartiMOSS/SharePoint-PowerShell/blob/master/SharePoint/Administration/PS_HowToDoCAMLQuery.ps1

Expand Recurring Events from a Sharepoint Calendar over WebServices?

The script is running, but the recurring events are not showing. What am I missing?


If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )  
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } 

$host.Runspace.ThreadOptions = "ReuseThread" 

#Definition of the function that allows to do the CAML query 
function DoCAMLQuery 
{ 
    param ($sSiteCollection,$sListName) 
    try 
    { 
        $spSite=Get-SPSite -Identity $sSiteCollection
        $spwWeb=$spSite.OpenWeb()        
        $splList = $spwWeb.Lists.TryGetList($sListName) 

        if ($splList)  
        {  
            $spqQuery = New-Object Microsoft.SharePoint.SPQuery 
            $spqQuery.Query =  
                "<GetListItems
    xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
    <listName>'Event Calendar'</listName>
    <query>
        <Query>
            <Where>
                <DateRangesOverlap>
                    <FieldRef Name='EventDate' />
                    <FieldRef Name='EndDate' />
                    <FieldRef Name='RecurrenceID' />
                    <FieldRef Name='fRecurrence' />
                    <FieldRef Name='RecurrenceData' />
                    <Value Type='DateTime'><Year/>
                    </Value>
                </DateRangesOverlap>
            </Where>
        </Query>
    </query>
    <queryOptions>
        <QueryOptions>
            <ExpandRecurrence>TRUE</ExpandRecurrence>
        </QueryOptions>
    </queryOptions>
</GetListItems>" 

            $spqQuery.ExpandRecurrence = $true
            $splListItems = $splList.GetItems($spqQuery) 

            $iNumber=1 
            foreach ($splListItem in $splListItems) 
            { 
                write-host "File # $iNumber - Name: " $splListItem.Name " ," "Title:" $splListItem["ows_LinkTitle"] -ForegroundColor Green 
                $iNumber+=1 
            } 
        }      
        $spSite.Dispose() 
    } 
    catch [System.Exception] 
    { 
        write-host -f red $_.Exception.ToString() 
    } 
} 
Start-SPAssignment –Global 
#Calling the function 
$sSiteCollection="http://sharepoint/" 
$sListName="Compliance Events"
DoCamlQuery -sSiteCollection $sSiteCollection -sListName $sListName 
Stop-SPAssignment –Global 

Remove-PSSnapin Microsoft.SharePoint.PowerShell

Thanks!
S
Shneor
  • 57
  • 7
  • Related: [CAML query on a SharePoint 2010 List?](https://stackoverflow.com/questions/8383616/caml-query-on-a-sharepoint-2010-list) – JosefZ Aug 15 '19 at 10:28
  • Hi @JosefZ, I am not sure what are your intentions with this url. Can you please point to the issue? Cheers! – Shneor Aug 15 '19 at 22:47

1 Answers1

0

Below sample script will return events from Now() till next two years.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$siteURL="http://sp"
$site = Get-SPSite $siteURL
$web = $site.OpenWeb()
$splList = $web.Lists.TryGetList("MyCalendar")
$spqQuery = New-Object Microsoft.SharePoint.SPQuery 
$spqQuery.Query = "<Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Now /></Value></DateRangesOverlap></Where>";
$spqQuery.ExpandRecurrence = $true


$splListItems = $splList.GetItems($spqQuery) 
Write-Host $splListItems.Count      

One thread for your reference

Lee
  • 5,305
  • 1
  • 6
  • 12