Data Migration in SharePoint 2010 – Only image files

Hello People,

This post is pertaining to the Documents Migration activity in SharePoint 2010 from a Shared File Server.  In this project, all documents (.doc, .xls,.pdf, others ) except media and image files are migrated because we wanted to clean up the media files and then migrate. After cleaning up from 300Gb to 20Gb we decided to migrate 4 GB of image files on SharePoint, in the same category in which our data and meta data was in the file server, since we already moved the documents.

This was challenging because the naming convention of image files on file server was incompatible with SharePoint naming convention, like SharePoint 2010 doesn’t allow ” & ” and other special characters to be in the file name or ” .” full stop so I had to write a script in which these things are also taken care of. I had the names of the image files in an excel document with jpg extension and below steps were followed for images migration in SharePoint with same category of meta data:

1 – Make a new list in SharePoint as ” Export to Excel” List.

2 – Export the excel MIS in SharePoint. This excel MIS had names of the jpg images that I wanted to transfer, select the particular column and export to a new list

3 – Open SharePoint Management Power Shell and run below script as administrator.



Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Start-SPAssignment -Global
##Site Collection
$siteCollUrl = <http://sharepoint_portal/libraryname&#8221;
##Document Lib
$libraryName = “Library_name”
##Physical Path
$ImageFileLocation = “filepathlocation”
$spSourceWeb = Get-SPWeb $siteCollUrl;
$spSourceList = $spSourceWeb.Lists[$libraryName];
$files = ([System.IO.DirectoryInfo] (Get-Item $ImageFileLocation)).GetFiles()
foreach($file in $files)
$filestream = ([System.IO.FileInfo](Get-Item $file.FullName)).OpenRead()
$folder = $spSourceWeb.getfolder($libraryName)
$spFile = $folder.Files.Add($folder.Url + “/” + $file.Name,[System.IO.Stream]$filestream, $true)

$FilePathList = $spSourceWeb.Lists[“ImagePaths”]
foreach ($listItem in $FilePathList.Items)
$file=Get-Item $listItem.Title
$FilePathList = $file.DirectoryName.Substring(9)
$FilePathListReplace = $FilePathList.Replace(“&”,”and”)

$filestream = ([System.IO.FileInfo](Get-Item $file.FullName)).OpenRead()
$folder = $spSourceWeb.GetFolder( “http://sharepoint/ImgFiles&#8221; + $FilePathListReplace)
$spFile = $folder.Files.Add($folder.Url + “/” + $file.Name,[System.IO.Stream]$filestream,$true)

Write-Host $listItem.Title


Stop-SPAssignment -Global


4 –  After success, check the library and image files being updated on portal. See the naming change from ” & ” to ” and “.


In this way you can migrate image files or media files from SharePoint Library to your meta data category, but please make sure the directory structure  is already defined in SharePoint.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.