Get SharePoint List Contents with Powershell using Client Side Object Model

So I had a situation the other day where I needed to get a SharePoint list exported as a CSV file on a regular occurance.

Some background, I was working through a process identifying critical information in SharePoint we would like on hand in the event all servers were down (i.e. a brown pants moment). While we have this pretty much sorted for various word and excel documents, there were a number of SharePoint lists that would also be invaluable, and I was loathe to turn these into a static excel spreadsheet instead.

Our current process is a manual one where the list is opened in Excel then saved as a CSV. As this requires human effort, humans get complacent, and doing repetative things over time get done poorly, shortcuts taken, shiny things to distract you, etc.. etc, and isn’t that one of the reasons we use computers?? Where was I going with this again? Ohhh look a Blue Car!

Right back on track… So I performed some research, got distracted, got a coffee, then got back to it.  A number of solutions exist which rely on the SharePoint powershell cmdlets that are installed on the SharePoint server, but do not come stand alone for a client. So that discounted them, also in our environment we are are not using PSRemoting. I’m also not a fan of running scheduled scripts on our SharePoint server unless absolutely necessary.

Then I stumbled across the SharePoint Client Side Object Module. Here I could manipulate SharePoint directly from my PC utilizing API calls on HTTPS. It sounded like just the ticket!

I dutily downloaded them: https://www.microsoft.com/en-nz/download/details.aspx?id=35585

Got a little confused reading the basic operations MSDN stuff https://msdn.microsoft.com/en-us/library/office/fp179912.aspx. This was in C# but translates fairly easily to Powershell with a bit of force.

Finally, after a bit of cursing, caffine, and luck I got a result! I wrapped it up in a function, then called it to my hearts content. Essentially it takes any SharePoint list and returns it as a table that I can then export to CSV.

Here is the Powershell:

Hopefully someone finds that useful, enjoy 😀

 

Leave a Reply

Your email address will not be published. Required fields are marked *