Skip to content

Commit 0117e7e

Browse files
committed
.
1 parent 066974d commit 0117e7e

11 files changed

+140
-14
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ settings.json
77
/FlowPowerAppsMigrator
88
Lists.xml
99
traceoutput.txt
10-
*.json
10+
/*.json

CompleteResourceMapping.ps1

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ if ($null -eq $TARGET_SITE_URL) {
77
$TARGET_SITE_URL = Read-Host "Enter the URL of the destination SharePoint site"
88
}
99
if($DoNotReconnect.IsPresent -eq $false){
10-
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
10+
if($USE_APP_ONLY_AUTHENTICATION){
11+
$TargetAppId = "0789bce2-cd45-4668-a20e-91e730c70861"
12+
$TargetAppSecret = "oRYj4s+2zBosk04X+AS+SQGKha/2BS4iek0mfd2PHsg="
13+
Connect-PnPOnline -Url $TARGET_SITE_URL -ClientId $TargetAppId -ClientSecret $TargetAppSecret -WarningAction Ignore
14+
}else{
15+
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
16+
}
1117
}
1218

1319
$lists = Get-PnPList -Includes Views, Fields, DefaultView

ConvertPackage.ps1

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
Add-Type -AssemblyName System.IO.Compression.FileSystem
1+
# This code is used to convert packages in the \src folder and save them to the \dist folder.
2+
# It first cleans any previously generated packages. It then gets a list of packages
3+
# from the \src folder with the .zip extension. It imports a CSV file containing
4+
# resource mapping information, and creates a dist folder if it does not exist.
5+
6+
# It then iterates through each package, extracting it to a destination folder
7+
# and replacing any old IDs with new ones from the resource mapping file.
8+
# If an MSAPP package is found, it extracts that too and replaces any old IDs
9+
# with new ones from the resource mapping file. It then creates a new zip file
10+
# for each package, either using tar or System.IO.Compression.ZipFile depending
11+
# on whether or not it is a solution package, and saves it to the \dist folder.
12+
13+
# Finally, it prints out a message that all packages have been converted and
14+
# saved to the \dist folder, and invokes
15+
# this directory in Windows Explorer so that its contents can be viewed.
16+
17+
18+
Add-Type -AssemblyName System.IO.Compression.FileSystem
219
$CurrentPath = (Get-Location).Path + "\"
320

421
# Clean previously generated packages

GenerateInitialMapping.ps1

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ if ($null -eq $SOURCE_SITE_URL) {
99

1010
Write-Host "[Attention] Look for a login popup in a separate window. Please, log in to the source site site $SOURCE_SITE_URL" -ForegroundColor Cyan
1111

12-
If ($CLEAR_CREDENTIALS_CACHE) {
12+
if($USE_APP_ONLY_AUTHENTICATION){
13+
Connect-PnPOnline -Url $SOURCE_SITE_URL -ClientId $SOURCE_SITE_APP_ID -ClientSecret $SOURCE_SITE_APP_SECRET -WarningAction Ignore
14+
}elseIf ($CLEAR_CREDENTIALS_CACHE) {
1315
Connect-PnPOnline -Url $SOURCE_SITE_URL -SPOManagementShell -ClearTokenCache -WarningAction Ignore
1416
}
1517
else {
16-
Connect-PnPOnline -Url $SOURCE_SITE_URL -UseWebLogin -WarningAction Ignore
18+
$appId = "0789bce2-cd45-4668-a20e-91e730c70861"
19+
$appSecret = "oRYj4s+2zBosk04X+AS+SQGKha/2BS4iek0mfd2PHsg="
20+
Connect-PnPOnline -Url $SOURCE_SITE_URL -ClientId $appId -ClientSecret $appSecret -WarningAction Ignore
21+
# Connect-PnPOnline -Url $SOURCE_SITE_URL -UseWebLogin -WarningAction Ignore
1722
}
1823

1924
try {

MISC/Convert-Packages.ps1

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ $Migration = @{
4141
$Migration = Get-FormItemProperties -item $Migration -dialogTitle "Enter target site" -propertiesOrder @("TARGET_SITE_URL")
4242
$TARGET_SITE_URL = $Migration.TARGET_SITE_URL
4343

44-
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
44+
if($USE_APP_ONLY_AUTHENTICATION){
45+
Connect-PnPOnline -Url $TARGET_SITE_URL -ClientId $TARGET_SITE_APP_ID -ClientSecret $TARGET_SITE_APP_SECRET -WarningAction Ignore
46+
}else{
47+
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
48+
}
49+
4550
$xmlFiles = Get-ChildItem *.xml
4651
if ($xmlFiles.Count -ne 0) {
4752
Write-Host Convert-Packages 1: $TARGET_SITE_URL Import of XML -ForegroundColor Yellow

MISC/migrator-config.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"target-site-url": "",
3+
"target-site-app-id":"",
4+
"target-site-app-secret":""
5+
}

Prepare-Deployment-Package-for-Client.ps1

+26-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ Get-ChildItem -Recurse | Unblock-File
3535
# Legacy PowerShell PnP Module is used because the new one has a critical bug
3636
Import-Module (Get-ChildItem -Recurse -Filter "*.psd1").FullName -DisableNameChecking
3737

38+
# Read migrator-config.json
39+
$MigratorConfig = Get-Content -Raw -Path "$Path\config\migrator-config.json" | ConvertFrom-Json
40+
3841
$Migration = @{
39-
SOURCE_SITE_URL = "https://contoso.sharepoint.com/sites/Site_A"
42+
SOURCE_SITE_URL = $MigratorConfig.'source-site-url'
4043
MIGRATE_LISTS = $true
4144
}
4245

@@ -45,6 +48,26 @@ $Migration = Get-FormItemProperties `
4548
-dialogTitle "Enter source site URL" `
4649
-propertiesOrder @("SOURCE_SITE_URL", "MIGRATE_LISTS")
4750

51+
$SOURCE_SITE_URL = $Migration.SOURCE_SITE_URL
52+
$SOURCE_SITE_APP_ID = $MigratorConfig.'source-site-app-id'
53+
$SOURCE_SITE_APP_SECRET = $MigratorConfig.'source-site-app-secret'
54+
55+
$areAllEmpty = [string]::IsNullOrEmpty($SOURCE_SITE_APP_ID) -and
56+
[string]::IsNullOrEmpty($SOURCE_SITE_APP_SECRET)
57+
58+
$areAllFilled = (![string]::IsNullOrEmpty($SOURCE_SITE_APP_ID)) -and
59+
(![string]::IsNullOrEmpty($SOURCE_SITE_APP_SECRET))
60+
61+
if ($areAllEmpty -or $areAllFilled) {
62+
Write-Host "\config\migrator-config.json file validation passed" -ForegroundColor Green
63+
} else {
64+
Write-Host "Validation failed: Please verify and ensure that either all properties are set or all variables are empty in \config\migrator-config.json" -ForegroundColor Red
65+
}
66+
67+
if($areAllFilled){
68+
$USE_APP_ONLY_AUTHENTICATION = $true
69+
}
70+
4871
$SOURCE_SITE_URL = $Migration.SOURCE_SITE_URL
4972
if ($Migration.MIGRATE_LISTS -like "true" -or
5073
$Migration.MIGRATE_LISTS -like "yes" -or
@@ -68,6 +91,8 @@ if ($MIGRATE_LISTS) {
6891
if ((Test-Path -Path "package\MISC") -eq $false) {
6992
New-Item -ItemType Directory -Force -Path "package\src" | Out-Null
7093
New-Item -ItemType Directory -Force -Path "package\MISC" | Out-Null
94+
New-Item -ItemType Directory -Force -Path "package\config" | Out-Null
95+
Copy-Item -Path "MISC\migrator-config.json" -Destination "package\config" -Recurse
7196
Copy-Item -Path "MISC\SharePointPnPPowerShellOnline" -Destination "package\MISC" -Recurse
7297
Copy-Item -Path "MISC\PS-Forms.ps1" -Destination "package\MISC"
7398
Copy-Item -Path "MISC\Move-Lists.ps1" -Destination "package\MISC"

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,27 @@ SharePoint List forms customized with Power Apps can be migrated if you follow t
169169

170170

171171
# Latest Updates
172+
### 3.9.0 Version - 2023-06-07
173+
174+
#### Changes
175+
- Added an ability to run migrations using SharePoint-only App ID and App Secret. Use the `config\migrator-config.json` file to do it:
176+
177+
```
178+
{
179+
"source-site-url": "",
180+
"target-site-url": "",
181+
"source-site-app-id":"",
182+
"source-site-app-secret":"",
183+
"target-site-app-id":"",
184+
"target-site-app-secret":""
185+
}
186+
```
187+
188+
#### Known issues
189+
- If the source and the target sites were created using different languages, then the app migrator will fail with the [Access is denied (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))](https://github.com/Zerg00s/FlowPowerAppsMigrator/issues/34) error.
190+
- Migrated lists with custom content types end up with an extra content type that should be deleted manually after migration.
191+
- Migrated lists might need fields to be added to the content type or a form. In some cases, migrated lists show only the Title in the edit form.
192+
172193
### 3.8.6 Version - 2023-05-10
173194

174195
#### Changes

RunAllScripts.ps1

+40-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Write-host
2626
Write-host "-----------------------------------------------------------------------------"
2727
Write-host
2828

29-
Set-PnPTraceLog -On -LogFile traceoutput.txt -Level Debug
29+
3030

3131
Set-Location $Path
3232
. .\MISC\PS-Forms.ps1
@@ -37,9 +37,14 @@ Get-ChildItem -Recurse | Unblock-File
3737
# and it's not possible to use it in the context of a non-admin user
3838
Import-Module (Get-ChildItem -Recurse -Filter "*.psd1").FullName -DisableNameChecking
3939

40+
Set-PnPTraceLog -On -LogFile traceoutput.txt -Level Debug
41+
42+
# Read migrator-config.json
43+
$MigratorConfig = Get-Content -Raw -Path "$Path\config\migrator-config.json" | ConvertFrom-Json
44+
4045
$Migration = @{
41-
SOURCE_SITE_URL = "https://contoso.sharepoint.com/sites/Site_A"
42-
TARGET_SITE_URL = "https://contoso.sharepoint.com/sites/Site_b"
46+
SOURCE_SITE_URL = $MigratorConfig.'source-site-url'
47+
TARGET_SITE_URL = $MigratorConfig.'source-site-url'
4348
MIGRATE_LISTS = $true
4449
CLEAR_CREDENTIALS_CACHE = $false
4550
}
@@ -51,6 +56,31 @@ $Migration = Get-FormItemProperties `
5156

5257
$SOURCE_SITE_URL = $Migration.SOURCE_SITE_URL
5358
$TARGET_SITE_URL = $Migration.TARGET_SITE_URL
59+
$SOURCE_SITE_APP_ID = $MigratorConfig.'source-site-app-id'
60+
$SOURCE_SITE_APP_SECRET = $MigratorConfig.'source-site-app-secret'
61+
$TARGET_SITE_APP_ID = $MigratorConfig.'target-site-app-id'
62+
$TARGET_SITE_APP_SECRET = $MigratorConfig.'target-site-app-secret'
63+
64+
$areAllEmpty = [string]::IsNullOrEmpty($SOURCE_SITE_APP_ID) -and
65+
[string]::IsNullOrEmpty($SOURCE_SITE_APP_SECRET) -and
66+
[string]::IsNullOrEmpty($TARGET_SITE_APP_ID) -and
67+
[string]::IsNullOrEmpty($TARGET_SITE_APP_SECRET)
68+
69+
$areAllFilled = (![string]::IsNullOrEmpty($SOURCE_SITE_APP_ID)) -and
70+
(![string]::IsNullOrEmpty($SOURCE_SITE_APP_SECRET)) -and
71+
(![string]::IsNullOrEmpty($TARGET_SITE_APP_ID)) -and
72+
(![string]::IsNullOrEmpty($TARGET_SITE_APP_SECRET))
73+
74+
if ($areAllEmpty -or $areAllFilled) {
75+
Write-Host "\config\migrator-config.json file validation passed" -ForegroundColor Green
76+
} else {
77+
Write-Host "Validation failed: Please verify and ensure that either all properties are set or all variables are empty in \config\migrator-config.json" -ForegroundColor Red
78+
}
79+
80+
if($areAllFilled){
81+
$USE_APP_ONLY_AUTHENTICATION = $true
82+
}
83+
5484
if ($Migration.MIGRATE_LISTS -like "true" -or
5585
$Migration.MIGRATE_LISTS -like "yes" -or
5686
$Migration.MIGRATE_LISTS -like "1"
@@ -78,18 +108,21 @@ if ($MIGRATE_LISTS) {
78108
}
79109

80110
Write-Host "[Attention] Look for a login popup in a separate window. Please, log in to the target site $TARGET_SITE_URL." -ForegroundColor Cyan
81-
If($CLEAR_CREDENTIALS_CACHE){
111+
if($USE_APP_ONLY_AUTHENTICATION){
112+
Connect-PnPOnline -Url $TARGET_SITE_URL -ClientId $TARGET_SITE_APP_ID -ClientSecret $TARGET_SITE_APP_SECRET -WarningAction Ignore
113+
}
114+
elseIf($CLEAR_CREDENTIALS_CACHE){
82115
Connect-PnPOnline -Url $TARGET_SITE_URL -SPOManagementShell -ClearTokenCache -WarningAction Ignore
83-
}else{
116+
}else{
84117
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
85118
}
86119

87120
# Verify the connection
88-
$Response = Invoke-PnPSPRestMethod -Url "$TARGET_SITE_URL/_api/web/currentUser"
121+
# $Response = Invoke-PnPSPRestMethod -Url "$TARGET_SITE_URL/_api/web/currentUser"
89122
Write-Host
90123
Write-Host Connected to the target site -ForegroundColor Green
91124
Write-Host "`tSite: $TARGET_SITE_URL" -ForegroundColor Yellow
92-
Write-Host "`tUser: $($Response.Title) ($($Response.Email))" -ForegroundColor Yellow
125+
# Write-Host "`tUser: $($Response.Title) ($($Response.Email))" -ForegroundColor Yellow
93126

94127

95128
if ($MIGRATE_LISTS) {

config/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
migrator-config-dev.json

config/migrator-config.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"source-site-url": "",
3+
"target-site-url": "",
4+
"source-site-app-id":"",
5+
"source-site-app-secret":"",
6+
"target-site-app-id":"",
7+
"target-site-app-secret":""
8+
}

0 commit comments

Comments
 (0)