I wanted to have a PowerShell script that downloaded A Document Library’s contents to a local folder. This is what I put together.
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()
[…] http://www.jbmurphy.com/2012/04/25/powershell-script-to-copy-a-sharepoint-document-library-to-a-loca… […]
[…] were added to the 2010 site into New documents libraries. These were backed up using this script and restored after every new test detach an attach test. This way all new code would be in place […]