I have a SharePoint online list with more than 9000 items and 22 column. The list is being populated on daily basis.

I am taking backup manually every morning by saving the list as excel file in the document library and in my local computer.

I need a Powershell script for SharePoint Online to save my list as xml file and then I can create a windows task to run it daily.

2 Answers 2


PowerShell for SharePoint Online has really limited capabilities at the moment. There is no one liner to automate this task. But you can use CSOM inside your scripts.

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint.Client') | Out-Null

$login = '[email protected]'
$password = ConvertTo-SecureString 'password' -AsPlainText -Force
$webUrl = 'https://test.sharepoint.com/sites/test/'
$listName = 'My List'

$context = New-Object Microsoft.SharePoint.Client.ClientContext $webUrl
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials $login, $password

$web = $context.Web
$list = $web.Lists.GetByTitle($listName)
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$items = $list.GetItems($query)


$items | Select @{ L = "Title"; E = { $_["Title"] } }, @{ L = "Created"; E = { $_["Created"] } } | Export-Csv -Path export.csv

Of course it is far from final solution. There are following issues with the script:

  • It loads data from all fields. Consider using ViewFields with the query to limit data loaded from database.
  • It loads all items from list which may cause SharePoint to denny your request if it exceeds trottling limits. Consider using RowLimit and paging.
  • In last line you can select required fields. You can also use one of ConvertTo-* methods to format your result.
  • Credentials are stored as plain text.

Here is the sample that explains the syntax:

Export-SPWeb -Identity "http://sp.dev/subsite" -ItemUrl "/subsite/lists/List Title here" -path "c:\output\tempfile.csv"

Some Where Options:

Identity: full url (absolute) of the site where the list exists

ItemUrl: relative path of the list from subsite level. Do not forget to include the leading “/”

Path: path of the output file to save the data in. This does not need any extension but I usually give it .txt.

There are lot more additional parameters but above are the minimum for copying a list

For more details please refer to below links:

How To Export/Import a List Using PowerShell

Use Windows PowerShell to export a site, list, or document library

  • This will only work for on-prem env. Question is about SharePoint Online. Oct 1, 2015 at 11:30
  • You are right @dstarkowski, this will not work on SharePoint online!
    – Jenny
    Oct 1, 2015 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.