Zhaobab
3/30/2015 - 12:28 PM

Download files from SharePoint site to local path, file links come from CSV file.

Download files from SharePoint site to local path, file links come from CSV file.

login;picture
rbla\rbla;rbla.jpg
rbla\jdiouf;jdiouf.jpg
rbla\ftri;ftri.jpg
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 17.04.2013
# Description: Download files from SharePoint site to local path, file links come from CSV file.
# ----------------------------------------------

# -- Initialize -- #
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

# -- Script -- #
$csv = Import-csv -Path ".\input.csv" -delimiter ";" 

## Get Credentials to access to the SharePoint Website
$Credential = Get-Credential
$WebRequest = new-object System.Net.WebClient
$WebRequest.Credentials =  $Credential.GetNetworkCredential()

## Get destination folder, or create it if doesn't exist
$destinationfolder = "C:\\Users\\blanchardro\\Desktop\\Download\\" 
if (!(Test-Path -path $destinationfolder))
{
	$dest = New-Item $destinationfolder -type directory
}
	
$csv | foreach {
	
	$sourceURL = "http://rbla-sp2010-002/UserPictures/" + $_.picture	
	$targetPATH = $destinationfolder + "\" + $_.picture
	try
	{
		$WebRequest.DownloadFile($sourceURL,$targetPATH)
		write-host $_.picture "Successfuly downloaded to $targetPATH !" -ForegroundColor green
	}
	catch
	{
		write-host "Error: $_" -ForegroundColor red
	}
}