Office 365 SharePoint Easy Migration Part 1

InfoPath alternatives for form designing SharePoint

Hi Everyone,
Today I will be sharing scripts which will be useful for migration of data to SharePoint Online.

Sometime we have the documents, files from any other application which we need to move to SharePoint .It’s quite time taking process if we have to upload the files manually to SharePoint Document Libraries.

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

Also check out some posts on:
– Apply term sets as Global Navigation in SharePoint site using PowerShell and CSOM

– Office 365 Easy Form Development FORM7

– Remove Sharepoint 2013 Quick Launch bar

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 LocalFolderPath value in XML input file.

Provide SharePoint library or folder inside 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

Hope this will help.

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


Similar SharePoint 2013 Tutorials

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 →

Leave a Reply