PnP Powershell update lookup columns TypeId (Content Type)

Harish Patil 21 Reputation points
2021-11-08T11:37:21.69+00:00

Hi Team,

We are migrating SharePoint 2013 to SharePoint Online. After migration we found that in list there is lookup column, it migrated as expected with ID. When I click on that lookup column value it popups new window with respective details of lookup column. But in that details Content Type column is there that is not migrated. Means it is showing default Content Type "Item" actually that value has some another content type "ListFieldsContentType". But as I understood as per below command it is updating "Participant" list content type. I want to update content type of City and Country. One thing if I open that value from parent City list there is already set the content type when I edit specific value it shows but not from "Participant" child list.

So I am trying to update using PnP PowerShell of each items lookup columns content type.

Is there any way how I can update? Kindly suggest.

Set-PnPListItem -List Participant -Identity $tListItem -ContentType "ListFieldsContentType" -Values @{"City" = $lookupSourceCity.TypeId; "Country"=$lookupSourceCountry.TypeId}

Thanks,
Harish Patil

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,543 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,649 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,567 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yi Lu_MSFT 17,451 Reputation points
    2021-11-09T09:40:13.633+00:00

    Hi @Harish Patil

    Set-PnPListItem -List "Demo List" -Identity $item -Values @{"Title" = "Test Title"; "Category"="Test Category"}  
    

    The code is to set fields value in the list item which has been retrieved by for instance Get-PnPListItem. It sets the content type of the item to "Company" and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields. So, it dose not apply to "City" and "Country" list.

    Here is how to change content type SharePoint online with PowerShell PnP Module:

    #Set Variables  
    $SiteURL = "https://crescent.sharepoint.com/sites/projects"  
    $ListName = "Project Proposal"  
    $OldContentTypeName = "Crescent Proposal V1"  
    $NewContentTypeName = "Crescent Project Proposal V2"  
       
    #Connect to PNP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
       
    #Get the New Content Type from the List  
    $NewContentType = Get-PnPContentType -List $ListName | Where {$_.Name -eq $NewContentTypeName}  
       
    #Get List Items of Old content Type  
    $ListItems = Get-PnPListItem -List $ListName -Query "<Query><Where><Eq><FieldRef Name='ContentType'/><Value Type='Computed'>$OldContentTypeName</Value></Eq></Where></Query>"  
    Write-host "Total Number of Items with Old Content Type:"$ListItems.count  
       
    ForEach($Item in $ListItems)  
    {  
        #Change the Content Type of the List Item  
        Set-PnPListItem -List $ListName -Identity $Item -ContentType $NewContentType  
    }  
    

    For more information, you could refer to:
    https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitem?view=sharepoint-ps
    https://www.sharepointdiary.com/2018/02/sharepoint-online-change-content-type-using-powershell.html

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.