Usage of Add-PnPContentTypesFromContentTypeHub

Harikrishnan P 1 Reputation point
2021-09-07T12:28:55.983+00:00

Hi,

Has anybody tried using the new command Add-PnPContentTypesFromContentTypeHub to sync content types from the hub to the site collection? I tried to use this command as per the documentation. But I'm getting an error as below.

Add-PnPContentTypesFromContentTypeHub : The type of data at position 249 is different than the one expected.
At line:1 char:1

  • Add-PnPContentTypesFromContentTypeHub -ContentTypes $list -Connection ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : WriteError: (:) [Add-PnPContentTypesFromContentTypeHub], InvalidOperationException
  • FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.ContentTypes.AddContentTypesFromContentTypeHub
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,728 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,387 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Limitless Technology 39,391 Reputation points
    2021-09-07T16:55:54.047+00:00

    Hello @Harikrishnan P

    I may recommend you to give a read to the sintex changes in SharePoint published last month. The "write error" seems like the input is not as expected.

    Check: https://techcommunity.microsoft.com/t5/sharepoint-syntex/syntex-product-updates-august-2021/ba-p/2606438

    Hope this helps you,
    Best regards


  2. Harikrishnan P 1 Reputation point
    2021-09-08T10:29:18.403+00:00

    I even tried in Azure runbook, I was getting the same error. We are using some content types based logic in the script,so according to Microsoft auto-syncing of content type will stop this month. So this is very critical .


  3. Yi Lu_MSFT 17,461 Reputation points
    2021-09-10T09:39:16.123+00:00

    Hi @Harikrishnan P
    Since I could not search any documents to explain this issue, I suggest you could open a service request in Microsoft 365 admin center for better help.
    131082-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  4. Harikrishnan P 1 Reputation point
    2021-09-15T09:38:22.103+00:00

    I have raised a ticket with Microsoft. They said PnP is not an MS product, so they can't do the support for the same. It's interesting that MS only suggested using this command. Considering that its only 2 weeks left to stop the automatic synchronization, it's really frustrating.


  5. Harikrishnan P 21 Reputation points
    2021-12-22T12:45:12.413+00:00

    This the code I'm currently using

    $ctHubUrl = Get-PnPContentTypePublishingHubUrl
    Connect-PnPOnline -Url $ctHubUrl
    $CTIds = Get-PnPContentType
    Write-Output 'Count:' $CTIds.Count
    $list = New-Object Collections.Generic.List[string]
    foreach($id in $CTIds)
    {
    $list.Add($id.Id.StringValue)
    }
    Add-PnPContentTypesFromContentTypeHub -ContentTypes $list -Connection $site
    Start-Sleep -s 60
    $SiteContnetTypes= Get-PnPContentType -InSiteHierarchy -Connection $site
    Write-Output 'Count:' $CTIds.Count

    After running this code I got the error 'The type of data at position 280 is different than the one expected.' But I confirmed that the count of content types in the hub and new site are the same using the above code.

    To verify the same using the UI I checked the Content-type gallery (/_layouts/15/SiteAdmin.aspx#/contentTypes) of the new site, I can see that all content types are added but if check the classic UI (/_layouts/15/mngctype.aspx) custom content types are not appearing there.

    Is this an expected behavior?

    What I want to do is, I want to add a content type to the list using a site design script. Previously we were relying on 1-hour delay to sync the content types to the new site. Now we removed it and tried the above code, but the problem is site design is not adding the content type to the list. I also tried the command Add-PnPContentTypeToList, which is also not working.

    This will work if we wait for 1 hour and the classic UI is populated with all the content types. Any idea on this issue?

    Note: I also noticed that even if we don't run the above code, immediately after creating the site Content type gallery (/_layouts/15/SiteAdmin.aspx#/contentTypes) will have all the custom content types populated by default. Not sure if this be the case once MS turn off content type sync in feb.

    0 comments No comments