Forum Discussion

Srinivas Pisipati's avatar
Srinivas Pisipati
Copper Contributor
Mar 23, 2018

Export SharePoint List to CSV and Upload to Document Library

Hello All,

 

I am the Owner of O365 SharePoint Site Collection. And we were maintaining a List with Team Members for P1 Availability. Columns are as below:

    Emp_ID                -- Single line text (Max. length 12)

    Emp_FullName    -- Single Line Text (Max. length 100)

    Emp_ShortID       -- Single line text (Max. length 16)

    Account_Name   -- Choice

    Account_Manager   -- People or Group

    Supporting_Technology    -- Choice

    Available_P1       -- Yes / No


We need a requirement to Export this List periodically (Weekly / Monthly) into CSV and Upload the File in Document Library. Could anyone please help in this regards, many thanks in advance.

 

Regards,

Srinivas P.

  • Hi All, I am looking for a solution through SharePoint Workflow / Script / etc..., but not with Microsoft Flow. Because I need to provide this site to a team, who dont have any SharePoint Knowledge. Thank you.

  • You can try below Powershell script to export list and run it periodically using task scheduler.  

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    
    #Get the Web
    $web = Get-SPWeb -identity "http://sp2013/sites/team"
    
    #Get the Target List
    $list = $web.Lists["CustomList36"]
    
    #Array to Hold Result - PSObjects
    $ListItemCollection = @()
    
    #CAML Query
    $spQuery = New-Object Microsoft.SharePoint.SPQuery
    $spQuery.ViewAttributes = "Scope='Recursive'";
    $spQuery.RowLimit = 2000
    $caml="<Where><Eq><FieldRef Name='Department'/><Value Type='Text'>D1</Value></Eq></Where>"
    $spQuery.Query = $caml
    
    #Get All List items
    $listItems=$list.GetItems($spQuery)
    foreach($item in $listItems) {
    	$ExportItem = New-Object PSObject 
    	$ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $item["Title"]
    	$ExportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $item["Department"]
    	
    	#Add the object with property to an Array
    	$ListItemCollection += $ExportItem
    }
    #Export the result Array to CSV file
    $ListItemCollection | Export-CSV "c:\Backup\ListData.csv" -NoTypeInformation                       
    
    #Dispose the web Object
    $web.Dispose()

    Export  

Resources