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.