How to write a SharePoint File to disk

It is quite common, there is a file in SharePoint, and you want to see it written to a local disk. How to do that in PowerShell? Here’s how:

$site = New-Object Microsoft.SharePoint.SPSite($SharePointLocation) 
$web = $site.OpenWeb() 
$item = $web.GetListItem($SharePointLocation) 
$fileStream = ( $item.file.OpenBinary())
$stream = New-Object System.IO.FileStream($LocalDiskFileLocation ,[System.IO.FileMode]::Create)
$writer = New-Object System.IO.BinaryWriter($stream)        
$writer.write($fileStream)        
$writer.Close()
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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