Quantcast
Channel: Active questions tagged powershell-3.0 - Stack Overflow
Viewing all articles
Browse latest Browse all 123

downloading a file from SharePoint Online with PowerShell

$
0
0

I have a requirement to download files from a sharepoint online document library using powershell

I've managed to get to the point where the download should happen but no luck.

I know its something to do with how I am using the stream/writer

any hints would be greatly appreciated

*Edit No error messages are thrown just 0 length files in my local Directory

$SPClient =  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")$SPRuntime = [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$folder = "PoSHTest"$destination = "C:\\test"$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)$web = $ctx.Web$lists = $web.Lists.GetByTitle($folder)$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(10000) $result = $lists.GetItems($query)$ctx.Load($Lists)$ctx.Load($result)$ctx.ExecuteQuery()#Edited the foreach as per @JNKforeach ($File in $result) {         Write-host "Url: $($File["FileRef"]), title: $($File["FileLeafRef"]) "        $binary = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($ctx,$File["FileRef"])        $Action = [System.IO.FileMode]::Create         $new = $destination +"\\"+ $File["FileLeafRef"]        $stream = New-Object System.IO.FileStream $new, $Action         $writer = New-Object System.IO.BinaryWriter($stream)        $writer.write($binary)        $writer.Close()

}


Viewing all articles
Browse latest Browse all 123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>