Pnpframework: ConvertTo-PnPPage from SharePoint 2016 to SharePoint Online fails

Created on 4 Mar 2021  路  13Comments  路  Source: pnp/pnpframework

Hi all,

I'm trying to use follow the guide below to convert SharePoint 2016 publishing pages to #modern using PnP.PowerShell

https://docs.microsoft.com/en-us/sharepoint/dev/transform/modernize-userinterface-site-pages-powershell#read-publishing-page-in-on-premises-sharepoint-and-create-the-modern-page-in-sharepoint-online

It fails with the following error:
ConvertTo-PnPPage : '>' is an unexpected token. The expected token is '='. Line 13, position 72.

Any idee on what's causing this?
I'm running PnP.PoweShell 1.3.0

Thanks

page transformation 馃 question

All 13 comments

@JimmyHang : please run with verbose logging and share the log. Also run get-pnpexception after the error and share that output

Hei @jansenbe,

Running the below command did not create any log file:
ConvertTo-PnPPage -Identity "temp.aspx" -PublishingPage -Overwrite -TargetConnection $target -LogVerbose -LogType File -LogFolder "C:\Development\Logs" -Connection $source

get-pnpexception gave me the following:

Message : '>' is an unexpected token. The expected token is '='. Line 13, position 74.
Stacktrace : at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at Microsoft.SharePoint.Client.ClientContextExtensions.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.SharePoint.Client.ClientContextExtensions.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PnP.Framework.AuthenticationManager.<>c.b__53_0(Object sender, WebRequestEventArgs webRequestEventArgs)
at System.EventHandler1.Invoke(Object sender, TEventArgs e) at Microsoft.SharePoint.Client.ClientRuntimeContext.OnExecutingWebRequest(WebRequestEventArgs args) at Microsoft.SharePoint.Client.ClientContext.GetWebRequestExecutor() at Microsoft.SharePoint.Client.ClientContext.<GetFormDigestInfoPrivateAsync>d__37.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.<EnsureFormDigestAsync>d__36.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.<ExecuteQueryAsync>d__28.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientObjectExtensions.<EnsurePropertyImplementation>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.SharePoint.Client.ClientObjectExtensions.EnsurePropertyT,TResult
at PnP.Framework.Modernization.Cache.CacheManager.GetPublishingPagesLibraryName(ClientContext context)
at PnP.PowerShell.Commands.Pages.ConvertToClientSidePage.ExecuteCmdlet()
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
ScriptLineNumber : 8

This sounds like an old bug we had when you used -UseWebLogin in PS. Can add the -Verbose flag to your PS connect-pnponline cmdlet call and ensure you're using the latest version?

@JimmyHang : were you able to cross check the version used?

@JimmyHang : can this issue be closed?

Hi @jansenbe, I'm sorry for the late reply, i think my issue might be related to networking, but I can't confirm it yet. If possible could we keep this open for the rest of the day. :) I'll keep you posted.

Cheers

@JimmyHang : any update here?

Hi @jansenbe, unfortunately I'm still having issuess accessing the internal network, I'll get back with an update tomorrow..

Hi @jansenbe, update on this issue, we're still having this issue inside the network. we're running 1.4 and it seems like PnP.PowerShell cannot connect to on-prem SharePoint, wonder if I'm missing some step?

Hi @jansenbe, update on this issue, I've managed to get past the "unexpected token issue", :) but the page still refuse to transform, error message: "Could not find file 'PnP.Framework.resources'.". I've tried to uninstall and re-install the module a couple of times, also tried with 1.4.0.0,

Below is the new trace, currentlyrunning 1.3.0.0. Very similar to this issue:
https://github.com/pnp/powershell/issues/200


PS C:\Users> $source = Connect-PnPOnline $sourceUrl -TransformationOnPrem -CurrentCredentials -ReturnConnection -Verbose
VERBOSE: PnP PowerShell Cmdlets (1.3.0.0)
PS C:\Users> ConvertTo-PnPPage -Identity "temp.aspx" -PublishingPage -Overwrite -TargetConnection $target -LogVerbose -LogType File -LogFolder "C:\Script\Logs" -Connection $source
ConvertTo-PnPPage : Could not find file 'PnP.Framework.resources'.
At line:1 char:1

  • ConvertTo-PnPPage -Identity "temp.aspx" -PublishingPage ...
  • ~~~~~~~~~~~~~~~~~

    • CategoryInfo : WriteError: (:) [ConvertTo-PnPPage], FileNotFoundException

    • FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Pages.ConvertToClientSidePage

      PS C:\Users> Get-PnPException

Message : Could not find file 'PnP.Framework.resources'.
Stacktrace : at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark&
stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetString(String name, CultureInfo culture) at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientObjectExtensions.<EnsurePropertyImplementation>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.SharePoint.Client.ClientObjectExtensions.EnsurePropertyT,TResult
at PnP.Framework.Modernization.Cache.CacheManager.GetPublishingPagesLibraryName(ClientContext context)
at PnP.PowerShell.Commands.Pages.ConvertToClientSidePage.ExecuteCmdlet()
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
ScriptLineNumber : 1

@JimmyHang : please ensure you've installed the latest nightly version (verify by adding -verbose to connect-pnponline) and then create a Fiddler trace of the failing connect to your on-premises SP2016 farm. Share the Fiddler trace + cmdline used via [email protected]. Note that to connect to on-premises SharePoint you need to use regular credentials (username + pwd), see below for a sample:

# Setup connection the target site - must be SPO and must be a modern site
$target = Connect-PnPOnline https://contoso.sharepoint.com/sites/moderncommunicationsite -ReturnConnection

# Connect to your on-premises portal
$source = Connect-PnPOnline https://portal2013.pnp.com/sites/classicportal -TransformationOnPrem -CurrentCredentials -ReturnConnection

# Convert a classic page living in the on-premises portal to a modern page in SharePoint Online. Dependent images and videos are copied as well from on-premises to online during this process.
ConvertTo-PnPPage -Identity "page1.aspx" -PublishingPage -TargetConnection $target -LogVerbose -LogType File -LogFolder c:\temp -Connection $source

Also cross check the PS version used, if you're using PS 5 you might wanna try using PS 7 and see if that makes a difference (PS 7 uses the .NET Core compiled bits while PS 5 uses the old .NET Framework compiled bits).

Thanks @jansenbe, and give it a go and get back to you. :)

Hi @jansenbe, I've downgraded PnP to: 3.26.2010.0 SharePointPnPPowerShellOnline
And direct conversion from SP2016 to SharePoint Online with below code now works for us. I'll close this issue.

#### transform directly
# Setup connection the target site - must be SPO and must be a modern site
$target = Connect-PnPOnline https://tentant.sharepoint.com/sites/site -UseWebLogin -ReturnConnection -Verbose

# Connect to your on-premises portal
$source = Connect-PnPOnline https://sp.onprem.com/sites/site -CurrentCredentials -ReturnConnection -Verbose

# Convert a classic page living in the on-premises portal to a modern page in SharePoint Online. Dependent images and videos are copied as well from on-premises to online during this process.
ConvertTo-PnPClientSidePage -Identity "cybersecurity-checklist.aspx" -PublishingPage -Overwrite `
        -CopyPageMetadata -KeepPageCreationModificationInformation `
        -PageLayoutMapping "mapping.xml" `
        -TargetConnection $target -LogVerbose -LogType File -LogFolder "C:\Logs"

Thanks

Was this page helpful?
0 / 5 - 0 ratings