I wanted to have a PowerShell script that downloaded A Document Library’s contents to a local folder. This is what I put together.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Function JBM-SharePoint-CopyDocumentLibraryLocal { PARAM([Parameter(Mandatory=$true)]$SiteURL, [Parameter(Mandatory=$true)]$DocumentLibrary, [Parameter(Mandatory=$true)]$Destination) $spWeb = Get-SPWeb -Identity http://$SiteURL $list = $spWeb.Lists[$DocumentLibrary] foreach ($listItem in $list.Items) { $DestinationPath = $listItem.Url.replace("$DocumentLibrary","$Destination").Replace("/","\") write-host "Downloading $($listItem.Name) -> $DestinationPath" if (!(Test-Path -path $(Split-Path $DestinationPath -parent))) { write-host "Createing $(Split-Path $DestinationPath -parent)" $dest = New-Item $(Split-Path $DestinationPath -parent) -type directory } $binary=$spWeb.GetFile($listItem.Url).OpenBinary() $stream = New-Object System.IO.FileStream($DestinationPath), Create $writer = New-Object System.IO.BinaryWriter($stream) $writer.write($binary) $writer.Close() } $spWeb.Dispose() |