@@ -33,6 +33,21 @@ Get-ChildItem -Recurse | Unblock-File
3333Import-Module (Get-ChildItem - Recurse- Filter" *.psd1" ).FullName- DisableNameChecking
3434
3535
36+ function Remove-SiteFieldFromXml {
37+ param (
38+ [Parameter (Mandatory = $true )]
39+ [string ]$fileName ,
40+
41+ [Parameter (Mandatory = $true )]
42+ [string ]$fieldName
43+ )
44+
45+ $fileContent = Get-Content $fileName
46+ $pattern = " <Field .*Name=`" $fieldName `" .*\/>"
47+ $updatedContent = $fileContent -replace $pattern , " "
48+ Set-Content - Path$fileName - Value$updatedContent
49+ }
50+
3651try {
3752$lists = Get-PnPList
3853}
@@ -81,7 +96,7 @@ if ($MigrationType -eq "Export") {
8196$exportContentTypes = $true ;
8297 }
8398 }
84- }
99+ }
85100
86101if ($exportContentTypes ) {
87102Get-PnPProvisioningTemplate - ListsToExtract$titles - Out" Lists.xml" - Handlers Lists, ContentTypes, Fields- Force- WarningAction Ignore
@@ -93,21 +108,23 @@ if ($MigrationType -eq "Export") {
93108# Remove all Property Bag entries from the lists. Begin
94109 ((Get-Content - Path Lists.xml- Raw- Encoding UTF8)-replace ' <\?xml version="1.0"\?>' , ' ' -replace ' RootSite' , ' Web' )| Set-Content - Path Lists.xml- Encoding UTF8
95110
111+ # Removing Site fields that cause the Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)
112+ Remove-SiteFieldFromXml - fileName" Lists.xml" - fieldName" TriggerFlowInfo"
113+ Remove-SiteFieldFromXml - fileName" Lists.xml" - fieldName" IsolatedDomain"
114+
96115$xml = [xml ](Get-Content Lists.xml)
97116
98-
99117$propertyBagEntries = $xml.GetElementsByTagName (' pnp:PropertyBagEntries' )
100118if ($propertyBagEntries -ne $null -and $propertyBagEntries.Count -gt 0 ) {
101119for ($i = $propertyBagEntries.Count - 1 ;$i -gt -1 ;$i -- ) {
102120$supress = $propertyBagEntries [$i ].ParentNode.RemoveChild($propertyBagEntries [$i ])
103- }
121+ }
104122 }
105123
106124$xml.Save (' Lists.xml' )
107125" <?xml version="" 1.0"" ?>`n " + (Get-Content " Lists.xml" - Raw- Encoding UTF8)| Set-Content " Lists.xml" - Encoding UTF8
108126
109127# Remove all Property Bag entries from the lists. End
110-
111128foreach ($title in $titles ) {
112129# Get the latest list item form layout. Footer, Header and the Body:
113130$list = Get-PnPList $title - Includes ContentTypes
@@ -118,7 +135,6 @@ if ($MigrationType -eq "Export") {
118135
119136if ($MigrationType -eq " Import" ) {
120137Write-Host " Importing lists and libraries..." - ForegroundColor Yellow
121-
122138
123139try {
124140 Apply- PnPProvisioningTemplate- Path Lists.xml
@@ -137,7 +153,6 @@ if ($MigrationType -eq "Import") {
137153throw
138154 }
139155
140-
141156$jsonFiles = Get-ChildItem * .json
142157if ($jsonFiles ) {
143158$titles = $jsonFiles | ForEach-Object {" $ ( $_.BaseName ) " }