Export SP Calendar List Items to csv with results showing only items over next 30 days with specified column values

sco gordo 301 Reputation points
2021-09-29T21:00:46.28+00:00

Hi, I'm trying to adapt https://www.sharepointdiary.com/2013/04/export-sharepoint-list-items-to-csv-using-powershell.html for a calendar, defining the Where-Object and limiting column output to

$list.Items | Where-Object { $["ContentTypeId"] -eq "0x0123456789"} | foreach {
$ExportItem = New-Object PSObject
$ExportItem | Add-Member -MemberType NoteProperty -name "EventDate" -value $
["EventDate"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "EndDate" -value $["EndDate"]
$ExportItem | Add-Member -MemberType NoteProperty -name "fAllDayEvent" -value $
["fAllDayEvent"]
$ExportItem | Add-Member -MemberType NoteProperty -name "UID" -value $_["UID"]

for items occurring within the next 30 days.

So far I'm not getting results. No errors either.

Any guidance appreciated.

Thanks

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,395 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,626 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,971 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,591 Reputation points
    2021-09-30T10:27:29.607+00:00

    Hi @sco gordo

    You could try the code as following:

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
       
    #Get the Web  
    $web = Get-SPWeb -Identity "url"  
       
    #Get the Target List  
    $list = $web.Lists["listname"]  
      
    #Array to Hold Result - PSObjects  
    $ListItemCollection = @()  
      
    #Today's date  
    $To = Get-date  
      
    #Date+30  
    $Date = (Get-date).AddDays(30)  
      
     $list.Items | Where-Object { $_["EventDate"] -le $Date -and $_["EventDate"] -ge $To}| foreach {  
     $ExportItem = New-Object PSObject  
     $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]  
     $ExportItem | Add-Member -MemberType NoteProperty -Name "EventDate" -value $_["EventDate"]  
      
       
     #Add the object with property to an Array  
     $ListItemCollection += $ExportItem  
     }  
     #Export the result Array to CSV file  
     $ListItemCollection | Export-CSV "c:\Listluyi.csv" -NoTypeInformation                         
       
    #Dispose the web Object  
    $web.Dispose()  
    

    Please change the paremeter as your need.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. sco gordo 301 Reputation points
    2021-09-30T16:22:37.94+00:00

    Much thanks, YiLu!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.