I want to download all documents and their versions from a SharePoint Online site.

I have tried achieving this by using a script by Nik Craik that I found here.
It doesn't work because it keeps throwing errors on Get-SPWeb commands. I suspect this is because I am using Sharepoint Online, so I replaced all instances of Get-SPWeb with Get-SPOSite.
I have confirmed that I have connected to my particular SharePoint site using Get-SPOSite. However, when I try this script with my modifications, I get no error reports, but there is nothing in the C:/Export folder.

How do I download documents and their versions from a SharePoint Online site?


You can not directly access a site collection or web in sharepoint online. Firstly you need to have context for the requested site:

   $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$webUrl = Read-Host -Prompt "HTTPS URL for your SP Online 2013 site" 
$username = Read-Host -Prompt "Email address for logging into that site"
$password = Read-Host -Prompt "Password for $username" -AsSecureString

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) 
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$web = $ctx.Web
$webs = $web.Webs

Courtesy: Sharing the experience

The powershell you are using is for on-premises sharepoint.

  • I voted your answer up but it doesn't show (not enough rep points). I realized I needed to work with on-premises SharePoint, so your answer was hugely helpful.
    – oymonk
    Jul 24 '15 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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