Monthly Archives: December 2023

Migrating a NAS based organization to Microsoft SharePoint and Microsoft 365 Groups

Here’s the context : you are a lawyer, working on many business cases. You rely on a local file server (NAS) to store all your contracts, documents, files. There’s one folder for each business case. You’re successful, and hire one employee, then another one. You also start collaborating with experts outside of your organization, and you need to manage collaborative work on all your Word, Excel, PowerPoint documents. You need to manage access to the files because not everyone has access to everything. Moreover, you’d like to follow who is doing what, and ease communication on each business case.

That’s when everything crumbles. Files get duplicated, you don’t know which version is the most up to date. Emails are out of control, because people tend to include the whole planet to ensure all persons concerned will receive their email, or at the opposite they click on “reply” instead of “reply all” and forget to keep updated a critical person.

Your wish list to Santa then becomes something like this :

  1. All my files should be stored in a single place, accessible from within and from outside my organization
  2. My files should be versionned, so that I can easily restore a previous version
  3. One must be able to edit concurrently a document, without facing potential painful merge process
  4. I should be able to easily grant or remove access to my files
  5. I would have a global strategy for access ocontrol to my documents, while still being able to fine tune permissions for specific resources or collaborators
  6. A web page or wiki, would give an overview of recent activity on each case
  7. A mail adress should be associated to the case, to ease document transmission
  8. I should be able to define tasks, and their owner, to keep track of Who’s doing What, When.
  9. A calendar would allow me to keep track of events related to each case

All this is what you would get by switching to a Microsoft 365 environment, through a SharePoint Team site for each case, coming with its associated Office 365 group, its default documents library, email addresse, home page, Ms planner plan for tasks management.

However, if you have an existing environment, with tens or hundreds of opened cases, migrating manually will require an awful lot of time, and will be error prone.

Happily, this can be automated using PowerShell scripts. Microsoft provides PowerShell extensions for its clound environments. However, we will rather use PnP PowerShell, “a cross-platform PowerShell Module providing over 650 cmdlets that work with Microsoft 365 environments”. This will make the creation of the SharePoint Team site, and of all the associated resources a breathe (or almost a breathe).

The PowerShell scripts below will take care of creating the SharePoint Team Site, and uploading to its documents library all files and folders from a local folder.

But first, you need PowerShell 7. On my Windows 11, the PowerShell Version was 5.1. You can manually download and install PowerShell 7 from the Windows Store, as described here.

Then, install Pnp PowerShell Module, as described here, or download the setup.ps1 script

Install-Module -Name PnP.PowerShell
Import-Module PnP.PowerShell

Then, given a folder, the targeted root SharePoint site, new site name and owner, and local folder to upload, the migrate.ps1 script will take care of creating the SharePoint site with the uploaded files. Ex :

.\migrate.ps1 'Affaire 123' '.\Affaire 123\' affaire-123 

The migrate.ps1 script :

if ($args.count -lt 5) {
	$scriptName = $MyInvocation.MyCommand.Name
	write-host "Utilisation:" $scriptName "<url racine du site sharepoint> <nom du site à créer> <répertoire à uploader> <owner email> <site email>"

#Config Variables
#$AdminSiteURL = ""
$AdminSiteURL = $args[0]
$displayName = $args[1]
$folder = $args[2]
$owner = $args[3]
$mailNickname = $args[4]

$description = $displayName
Try {
	#Connect to PnP Online
	Connect-PnPOnline -Url $AdminSiteURL -Interactive
	#Create a new Office 365 group
	# New-PnPMicrosoft365Group -DisplayName $displayName -MailNickname "HRAdmin" -Owners $owner -Members @($owner) -IsPrivate
	$site = New-PnPMicrosoft365Group -DisplayName $displayName -Description $description -MailNickname $mailNickname -Owners $owner -Members @($owner) -IsPrivate 

	write-host ($site | Format-Table | Out-String)

	& "./upload.ps1" $site.SiteURL $folder
Catch {
    write-host -f Red "Error:" $_.Exception.Message

Whic itself calls the upload.ps1 script to populate the ShrePoint documents library from the given local folder :

# Upload file to site

if ($args.count -lt 2) {
	$scriptName = $MyInvocation.MyCommand.Name
	write-host "Utilisation:" $scriptName "<url racine du site sharepoint> <répertoire à uploader>"

# What is the target SharePoint site URL for the upload? 
# $spoSite = '' 
$spoSite = $args[0] 

# What is the location of the files to upload? 
$localFolder = $args[1]

# What is the target document library relative to the site URL? 
$spoDocLibrary = "Documents partages"

Connect-PnPOnline -Url $spoSite -Interactive


function Upload-Folder {
	param (

    Write-host 'Uploading folder' $localFolder.toString() ' to ' $remoteFolder.toString()

    $resolvedRemoteFolder = Resolve-PnPFolder -SiteRelativePath $remoteFolder

    $files = Get-ChildItem $localFolder -File

    foreach ($file in $files) { 
        write-host 'Uploading file ' $file.FullName.ToString()
	$uploadedFile = Add-PnPFile -Path ($file.FullName.ToString()) -Folder $remoteFolder -Values @{"Title" = $($file.Name) } 

    $subfolders = Get-ChildItem $localFolder -Directory
    foreach ($subfolder in $subfolders) { 
	$folderName = Split-Path $subfolder.FullName -Leaf
        Upload-Folder -localFolder $subfolder.FullName -remoteFolder "$remoteFolder/$folderName/"


Upload-Folder -localFolder $localFolder -remoteFolder $spoDocLibrary

If the scripts, you should see the new site appear in your SharePoint admin portal, usually https://<tenant>