forked from Zerg00s/FlowPowerAppsMigrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompleteResourceMapping.ps1
75 lines (65 loc) · 2.56 KB
/
CompleteResourceMapping.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[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"
}
if($DoNotReconnect.IsPresent -eq $false){
if($USE_APP_ONLY_AUTHENTICATION){
Connect-PnPOnline -Url $TARGET_SITE_URL -ClientId $TARGET_SITE_APP_ID -ClientSecret $TARGET_SITE_APP_SECRET -WarningAction Ignore
}else{
Connect-PnPOnline -Url $TARGET_SITE_URL -UseWebLogin -WarningAction Ignore
}
}
$lists = Get-PnPList -Includes Views, Fields, DefaultView
$lists = $lists | Where-Object hidden -eq $false
$resources = Import-Csv -Path .\resourceMapping.csv
$resources[0].newId = $TARGET_SITE_URL
$lists | ForEach-Object {
$line = "" | Select-Object resource, oldId, newId
$line.resource = $_.RootFolder.ServerRelativeUrl.Replace($_.ParentWebUrl, "")
$line.newId = $_.ID
# There could be more than one resource:
$resource = $resources | Where-Object resource -eq $line.resource
if ($resource -ne $null) {
if(@($resource).Count -gt 1){
Write-Host "More than one resource found for $line.resource" -ForegroundColor Yellow
foreach($r in $resource){
$r.newId = $line.newId
}
}else{
$resource.newId = $line.newId
}
}
foreach ($view in $_.Views) {
$line = "" | Select-Object resource, oldId, newId
$line.resource = $view.ServerRelativeUrl.Replace($_.ParentWebUrl, "")
$line.newId = $view.ID
$resource = $resources | Where-Object resource -eq $line.resource
if ($resource -ne $null) {
if(@($resource).Count -gt 1){
Write-Host "More than one resource found for $line.resource" -ForegroundColor Yellow
foreach($r in $resource){
$r.newId = $line.newId
}
}else{
$resource.newId = $line.newId
}
}
}
$resource = $resources | Where-Object resource -eq $line.resource
if ($resource -ne $null) {
if(@($resource).Count -gt 1){
Write-Host "More than one resource found for $line.resource" -ForegroundColor Yellow
foreach($r in $resource){
$r.newId = $line.newId
}
}else{
$resource.newId = $line.newId
}
}
}
$resources | Export-Csv -Path "resourceMapping.csv" -NoTypeInformation
Write-Host Mapping file resourceMapping.csv fully complete -ForegroundColor Green