This code gets a list of all the pages in the “Site Pages” language folder.
Now that we have a list of all the pages, we need to loop through each page and reconnect its language variations. We can do this using a foreach loop:
1
2
3
foreach($Pagein$Pages){# Reconnect language variations for the page}
Inside the foreach loop, we need to get the default file for the page. We can do this using the Get-PnPFile cmdlet:
This code gets a information about language variations page by filtering the pages in the “Site Pages” library by Folder $Language-Variable and the $Page.Name.
Now that we have all the information we need, we can reconnect the language variations to the default file. We can do this using the Set-PnPListItem cmdlet:
1
2
#Set the Default Item fieldSet-PnPListItem-ListSitePages-Identity$DefaultFile.Id-Values@{"_SPTranslatedLanguages"=$LangISO}
1
2
#Set the Language Item fieldsSet-PnPListItem-ListSitePages-Identity$LangFile.Id-Values@{'_SPIsTranslation'='1';'_SPTranslationLanguage'=$LangISO;'_SPTranslationSourceItemId'=$DefaultFile.FieldValues.UniqueId}
This code sets the _SPTranslationSourceItemId property of the variation file to the GUID of the default file.
That’s it! We’ve now looped through all the pages and their language variations, and reconnected them to each other.
Conclusion
In this blog post, we’ve walked through the PowerShell code for reconnecting pages with language variations after copying them with ShareGate. By using this code, you can ensure that the language variations are properly connected to each other, and that they are displayed correctly on the site.
Here’s the complete PowerShell script for reconnecting pages with language variations after copying them with ShareGate:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$SiteCollection="https://contoso.sharepoint.com/sites/SiteCollection"$Language="de"$LangISO="de-de"#Create ConnectionConnect-PnPOnline-Url$SiteCollection-Interactive#Get all aspx pages within Folder DE in Library SitePages$Pages=Get-PnPFolderItem-FolderSiteRelativeUrlSitePages/$Language#Loop through all files and get the file object from the files with the same name in the root directoryforeach($Pagein$Pages){$DefaultFile=Get-PnPFile-UrlSitePages/$($Page.Name)-AsListItem$LangFile=Get-PnPFile-UrlSitePages/$Language/$($Page.Name)-AsListItem#Set the Default Item fieldSet-PnPListItem-ListSitePages-Identity$DefaultFile.Id-Values@{"_SPTranslatedLanguages"=$LangISO}#Set the German Language Item fieldsSet-PnPListItem-ListSitePages-Identity$LangFile.Id-Values@{'_SPIsTranslation'='1';'_SPTranslationLanguage'=$LangISO;'_SPTranslationSourceItemId'=$DefaultFile.FieldValues.UniqueId}}
Comments
You can use your Bluesky account to
reply
to this post. Learn how this is implemented
here.