Office 365 SharePoint Easy Migration Part 1

Hi Everyone, Today I will be sharing scripts which will be useful for migration of data to SharePoint online (Download PDF for FREE). Sometimes we have the documents, files from any other application which we need to move to SharePoint.It’s quite a time taking process if we have to upload the files manually to SharePoint Document Libraries.

I had a requirement where the client provided huge documents from a legacy application and we had to move all the files to SharePoint document libraries.

SharePoint deveopment training course

So lets scripting to automate solution.

Please place the input values in below XML. Create Local folder named as “Documents” where you have kept the .ps1 file. You can provide any name and accordingly update the LocalFolderPath value in XML input file.

Provide SharePoint library or folder inside the library in SPfolderPath XML property.

We can have multiple <UploadFile> tag to define multiple SharePoint file location and respective document folder location.

<?xml version=”1.0″ encoding=”utf-8″?>
<WebSite Url=”” >
<UploadFile LocalFolderPath=”Documents” SPfolderPath=”SampleDoc”/>

Script Code-

$0 = $MyInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
$xmlFilePath = $(“$dp0\Inputs.xml”)
$xmldata = [xml](Get-Content($xmlFilePath));

$username = “”
$password = Read-Host -Prompt “Please enter your password” -AsSecureString

$url = $xmldata.WebSite.Url

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials

Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.Publishing.dll”
Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.Taxonomy.dll”

if (!$clientContext.ServerObjectIsNull.Value)
Write-Host “Connected to SharePoint Online site: ‘$Url'” -ForegroundColor Green

$web = $clientContext.Web


function UploadFiles([Microsoft.SharePoint.Client.Web] $web)

foreach($uploadFile in $xmldata.WebSite.UploadFiles.UploadFile)

$FolderLocation = $(“$dp0\$location”)

foreach ($File in (dir $FolderLocation))
$FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File



UploadFiles $web

You  may like following SharePoint migration tutorials:

Hope this will help. I will be sharing code to import data in CSV format to SharePoint List.


Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →