Skip to content

Commit

Permalink
Added ability to migrate lists and libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerg00s committed Oct 24, 2021
1 parent 58535dd commit 6f6620b
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ resourceMapping.csv
settings.json
/temp
/dist
/samples
/samples
/package
/FlowPowerAppsMigrator
Lists.xml
*.json
11 changes: 9 additions & 2 deletions CompleteResourceMapping.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
if ($null -eq $TARGET_SITE_URL) {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[switch]$DoNotReconnect
)
if ($null -eq $TARGET_SITE_URL) {
$TARGET_SITE_URL = Read-Host "Enter the URL of the destination SharePoint site"
}
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
if($DoNotReconnect.IsPresent -eq $false){
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
}

$lists = Get-PnPList -Includes Views, Fields, DefaultView
$lists = $lists | Where-Object hidden -eq $false
Expand Down
16 changes: 14 additions & 2 deletions GenerateInitialMapping.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
if($null -eq $SOURCE_SITE_URL){
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string]$DestinationFolder = $null
)
if ($null -eq $SOURCE_SITE_URL) {
$SOURCE_SITE_URL = Read-Host "Enter the URL of the original (old) SharePoint site"
}

Expand All @@ -25,5 +30,12 @@ $lists | ForEach-Object {
$resources += $line
}

$resources | Export-Csv -Path "resourceMapping.csv" -NoTypeInformation
if ($DestinationFolder) {
$destinationCsvPath = Join-Path $DestinationFolder "resourceMapping.csv"
}
else {
$destinationCsvPath = "resourceMapping.csv"
}

$resources | Export-Csv -Path $destinationCsvPath -NoTypeInformation
Write-Host resourceMapping.csv generated -ForegroundColor Green
3 changes: 3 additions & 0 deletions MISC/Convert-Packages.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
PowerShell.exe -Command "& '.\Convert-Packages.ps1' -path '%~dp0'"
PAUSE
50 changes: 50 additions & 0 deletions MISC/Convert-Packages.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
param (
[string]$Path
)
# Created by Denis Molodtsov (@Zerg00s) in 2018

$ErrorActionPreference = "Stop"

$host.UI.RawUI.WindowTitle = "Flow & Power Apps Migrator"

Write-host
Write-host
Write-Host " ______ _ _____ " -ForegroundColor Yellow
Write-Host " | ____| | ___ | __ \ " -ForegroundColor Yellow
Write-Host " | |__ | | _____ __ ( _ ) | |__) |____ _____ _ __ " -ForegroundColor Yellow
Write-Host " | __| | |/ _ \ \ /\ / / / _ \/\ | ___/ _ \ \ /\ / / _ \ `'__| " -ForegroundColor Yellow
Write-Host " | | | | (_) \ V V / | (_> < | | | (_) \ V V / __/ | " -ForegroundColor Yellow
Write-Host " |_| |_|\___/ \_/\_/ \___/\/_|_| \___/ \_/\_/ \___|_| " -ForegroundColor Yellow
Write-Host " /\ | \/ (_) | | " -ForegroundColor Cyan
Write-Host " / \ _ __ _ __ ___ | \ / |_ __ _ _ __ __ _| |_ ___ _ __ " -ForegroundColor Cyan
Write-Host " / /\ \ | `'_ \| `'_ \/ __| | |\/| | |/ _`` | `'__/ _`` | __/ _ \| `'__|" -ForegroundColor Cyan
Write-Host " / ____ \| |_) | |_) \__ \ | | | | | (_| | | | (_| | || (_) | | " -ForegroundColor Cyan
Write-Host " /_/ \_\ .__/| .__/|___/ |_| |_|_|\__, |_| \__,_|\__\___/|_| " -ForegroundColor Cyan
Write-Host " | | | | __/ | " -ForegroundColor Cyan
Write-Host " |_| |_| |___/ " -ForegroundColor Cyan
Write-host
Write-host "-----------------------------------------------------------------------------"
Write-host


Set-Location $Path
. .\MISC\PS-Forms.ps1

Get-ChildItem -Recurse | Unblock-File
# Legacy PowerShell PnP Module is used because the new one has a critical bug
Import-Module (Get-ChildItem -Recurse -Filter "*.psd1").FullName -DisableNameChecking

$Migration = @{
TARGET_SITE_URL = "https://contoso.sharepoint.com/sites/Site_b"
}

$Migration = Get-FormItemProperties -item $Migration -dialogTitle "Enter target site" -propertiesOrder @("TARGET_SITE_URL")
$TARGET_SITE_URL = $Migration.TARGET_SITE_URL

Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
$xmlFiles = Get-ChildItem *.xml
if($xmlFiles.Count -ne 0){
. .\MISC\Move-Lists.ps1 -Path $Path -MigrationType Import -TargetSite $TARGET_SITE_URL
}
. .\CompleteResourceMapping.ps1 -DoNotReconnect
. .\ConvertPackage.ps1
72 changes: 72 additions & 0 deletions MISC/Move-Lists.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[CmdletBinding()]
param (
[Parameter()]
[string]$Path,

[Parameter(Mandatory = $true)]
[ValidateSet('Export', 'Import')]
[string]$MigrationType,

[Parameter(Mandatory = $false)]
[string]$SourceSite,

[Parameter(Mandatory = $false)]
[string]$TargetSite
)


#-----------------------------------------------------------------------
# Script lets you migrate one or more SharePoint lists from source site
# To destination site
# Denis Molodtsov, 2021
#-----------------------------------------------------------------------

$ErrorActionPreference = "Stop"

Clear-Host

Write-Host $Path -ForegroundColor Green

Set-Location $Path
. .\MISC\PS-Forms.ps1

Get-ChildItem -Recurse | Unblock-File
# Legacy PowerShell PnP Module is used because the new one has a critical bug
Import-Module (Get-ChildItem -Recurse -Filter "*.psd1").FullName -DisableNameChecking

if ($MigrationType -eq "Export") {
Get-ChildItem *.xml | ForEach-Object { Remove-Item -Path $_.FullName }
Get-ChildItem *.json | ForEach-Object { Remove-Item -Path $_.FullName }
$lists = Get-PnPList
$lists = $lists | Where-Object { $_.Hidden -eq $false }

$selectedLists = Get-FormArrayItems ($lists) -dialogTitle "Select lists and libraries to migrate" -key Title
$titles = $selectedLists.Title
Get-pnpProvisioningTemplate -ListsToExtract $titles -Out "Lists.xml" -Handlers Lists -Force -WarningAction Ignore
((Get-Content -path Lists.xml -Raw) -replace 'RootSite', 'Web') | Set-Content -Path Lists.xml
foreach ($title in $titles) {
# Get the latest list item form layout. Footer, Header and the Body:
$list = Get-PnPList $title -Includes ContentTypes
$contentType = $list.ContentTypes | Where-Object { $_.Name -eq "Item" }
$contentType.ClientFormCustomFormatter | Set-Content .\$title.json
}
}

if ($MigrationType -eq "Import") {
Apply-PnPProvisioningTemplate -Path Lists.xml
$jsonFiles = Get-ChildItem *.json
if ($jsonFiles) {
$titles = $jsonFiles | ForEach-Object { "$($_.BaseName)" }

foreach ($title in $titles) {
$list = Get-PnPList $title -Includes ContentTypes
$contentType = $list.ContentTypes | Where-Object { $_.Name -eq "Item" }
if ($contentType) {
$json = Get-Content .\$title.json
$contentType.ClientFormCustomFormatter = $json
$contentType.Update($false)
$contentType.Context.ExecuteQuery();
}
}
}
}
3 changes: 3 additions & 0 deletions Prepare-Deployment-Package-for-Client.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
PowerShell.exe -Command "& '.\Prepare-Deployment-Package-for-Client.ps1' -path '%~dp0'"
PAUSE
91 changes: 91 additions & 0 deletions Prepare-Deployment-Package-for-Client.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
param (
[string]$Path
)
# Created by Denis Molodtsov (@Zerg00s) in 2018

$ErrorActionPreference = "Stop"

$host.UI.RawUI.WindowTitle = "Flow & Power Apps Migrator"

Write-host
Write-host
Write-Host " ______ _ _____ " -ForegroundColor Yellow
Write-Host " | ____| | ___ | __ \ " -ForegroundColor Yellow
Write-Host " | |__ | | _____ __ ( _ ) | |__) |____ _____ _ __ " -ForegroundColor Yellow
Write-Host " | __| | |/ _ \ \ /\ / / / _ \/\ | ___/ _ \ \ /\ / / _ \ `'__| " -ForegroundColor Yellow
Write-Host " | | | | (_) \ V V / | (_> < | | | (_) \ V V / __/ | " -ForegroundColor Yellow
Write-Host " |_| |_|\___/ \_/\_/ \___/\/_|_| \___/ \_/\_/ \___|_| " -ForegroundColor Yellow
Write-Host " /\ | \/ (_) | | " -ForegroundColor Cyan
Write-Host " / \ _ __ _ __ ___ | \ / |_ __ _ _ __ __ _| |_ ___ _ __ " -ForegroundColor Cyan
Write-Host " / /\ \ | `'_ \| `'_ \/ __| | |\/| | |/ _`` | `'__/ _`` | __/ _ \| `'__|" -ForegroundColor Cyan
Write-Host " / ____ \| |_) | |_) \__ \ | | | | | (_| | | | (_| | || (_) | | " -ForegroundColor Cyan
Write-Host " /_/ \_\ .__/| .__/|___/ |_| |_|_|\__, |_| \__,_|\__\___/|_| " -ForegroundColor Cyan
Write-Host " | | | | __/ | " -ForegroundColor Cyan
Write-Host " |_| |_| |___/ " -ForegroundColor Cyan
Write-host
Write-host "-----------------------------------------------------------------------------"
Write-host

Write-Host "This script will produce a sharable package that your Client or Partner can use for deployments" -ForegroundColor Yellow

Set-Location $Path
. .\MISC\PS-Forms.ps1

Get-ChildItem -Recurse | Unblock-File
# Legacy PowerShell PnP Module is used because the new one has a critical bug
Import-Module (Get-ChildItem -Recurse -Filter "*.psd1").FullName -DisableNameChecking

$Migration = @{
SOURCE_SITE_URL = "https://contoso.sharepoint.com/sites/Site_A"
MIGRATE_LISTS = $true
}

$Migration = Get-FormItemProperties `
-item $Migration `
-dialogTitle "Enter source site URL" `
-propertiesOrder @("SOURCE_SITE_URL", "MIGRATE_LISTS")

$SOURCE_SITE_URL = $Migration.SOURCE_SITE_URL
if ($Migration.MIGRATE_LISTS -like "true" -or
$Migration.MIGRATE_LISTS -like "yes" -or
$Migration.MIGRATE_LISTS -like "1"
) {
$Migration.MIGRATE_LISTS = $true
}
else {
$Migration.MIGRATE_LISTS = $false
}
$MIGRATE_LISTS = $Migration.MIGRATE_LISTS


# Preparing package for the client
New-Item -ItemType Directory -Force -Path "package" | Out-Null
. .\GenerateInitialMapping.ps1 -DestinationFolder ".\package"
if ($MIGRATE_LISTS) {
. .\MISC\Move-Lists.ps1 -Path $Path -MigrationType Export -SourceSite $SOURCE_SITE_URL
}

if ((Test-Path -Path "package\MISC") -eq $false) {
New-Item -ItemType Directory -Force -Path "package\src" | Out-Null
New-Item -ItemType Directory -Force -Path "package\MISC" | Out-Null
Copy-Item -Path "MISC\SharePointPnPPowerShellOnline" -Destination "package\MISC" -Recurse
Copy-Item -Path "MISC\PS-Forms.ps1" -Destination "package\MISC"
Copy-Item -Path "MISC\Move-Lists.ps1" -Destination "package\MISC"
Copy-Item -Path "MISC\Convert-Packages.ps1" -Destination "package"
Copy-Item -Path "MISC\Convert-Packages.bat" -Destination "package"
Copy-Item -Path "Lists.xml" -Destination "package"

Get-ChildItem *.json | ForEach-Object {
Copy-Item -Path $_.Name -Destination "package"
}

Copy-Item -Path "ConvertPackage.ps1" -Destination "package"
Copy-Item -Path "CompleteResourceMapping.ps1" -Destination "package"
}

Write-host '[Important] Next steps' -ForegroundColor Yellow
Write-host "1) Export your Power Apps And Flows" -ForegroundColor Yellow
Write-host "2) Place all of these exported ZIP files to the package\src folder" -ForegroundColor Yellow
Write-host "3) Share the package directory with your Client or Partner" -ForegroundColor Yellow
Write-host "4) Instruct your Client or Partner to run Convert-Packages.bat on their end" -ForegroundColor Yellow
Write-host "5) Instruct your Client or Partner deploy all converted Apps and Flows from \dist directory" -ForegroundColor Yellow
26 changes: 23 additions & 3 deletions RunAllScripts.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
param (
[string]$Path
)
# Created by Denis Molodtsov, 2018, @Zerg00s
# Created by Denis Molodtsov (@Zerg00s) in 2018

$ErrorActionPreference = "Stop"

Expand Down Expand Up @@ -37,13 +37,33 @@ Import-Module (Get-ChildItem -Recurse -Filter "*.psd1").FullName -DisableNameChe
$Migration = @{
SOURCE_SITE_URL = "https://contoso.sharepoint.com/sites/Site_A"
TARGET_SITE_URL = "https://contoso.sharepoint.com/sites/Site_b"
MIGRATE_LISTS = $true
}

$Migration = Get-FormItemProperties -item $Migration -dialogTitle "Enter source and target sites" -propertiesOrder @("SOURCE_SITE_URL", "TARGET_SITE_URL")
$Migration = Get-FormItemProperties `
-item $Migration `
-dialogTitle "Enter source and target sites" `
-propertiesOrder @("SOURCE_SITE_URL", "TARGET_SITE_URL", "MIGRATE_LISTS")

$SOURCE_SITE_URL = $Migration.SOURCE_SITE_URL
$TARGET_SITE_URL = $Migration.TARGET_SITE_URL
if ($Migration.MIGRATE_LISTS -like "true" -or
$Migration.MIGRATE_LISTS -like "yes" -or
$Migration.MIGRATE_LISTS -like "1"
) {
$Migration.MIGRATE_LISTS = $true
}
else {
$Migration.MIGRATE_LISTS = $false
}
$MIGRATE_LISTS = $Migration.MIGRATE_LISTS

. .\GenerateInitialMapping.ps1
if ($MIGRATE_LISTS) {
. .\MISC\Move-Lists.ps1 -Path $Path -MigrationType Export -SourceSite $SOURCE_SITE_URL
}
. .\CompleteResourceMapping.ps1
. .\ConvertPackage.ps1
if ($MIGRATE_LISTS) {
. .\MISC\Move-Lists.ps1 -Path $Path -MigrationType Import -TargetSite $TARGET_SITE_URL
}
. .\ConvertPackage.ps1

0 comments on commit 6f6620b

Please sign in to comment.