Change Content Type of Existing Items in SharePoint using PowerShell

Requirement:
We’ve an existing document library with 100’s of Sales proposal documents in it. To enforce standardization, sales team created a content type “Sales Proposal”. We got a requirement to change content type of all existing documents stored in a particular document library with the default content type “Document”. In other words, All the documents now need to be assigned a new content type “Sales Proposal”.

How to change content type of existing Items (documents) in SharePoint?

You can change the content type of the existing items by getting into the edit properties page of the particular item and switching “Content Type” field.

sharepoint powershell change item content type

While its relatively easy and straightforward to change the content type of existing items in SharePoint, you do not want to go through each and every single document in the document library and manually assign the new content type to it, as it will be time-consuming, isn’t it?

Well, let us use PowerShell to make it quick and easy! This script iterates through all documents stored in the given document library, checks for the content type of each document and if it is a specific content type, it replaces the old content type with the new content type.

Before running this script, Add your new content type to your library first! Find my script: Add Content Type to SharePoint Library using PowerShell

PowerShell script to change item content type in SharePoint

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom PowerShell Function to switch Content type of all items stored in a SharePoint library
Function Change-ItemContentType {
    param(
        [Microsoft.SharePoint.SPWeb]$Web = $(throw "Please provide the 'Web' Parameter!"),
        [string]$ListName = $(throw "Please provide the 'ListName' Parameter!"),
        [string]$OldContentTypeName = $(throw "Please provide the 'OldContentTypeName' Parameter!"),
        [string]$NewContentTypeName = $(throw "Please provide the 'NewContentTypeName' Parameter!")
    )    
 
    #Get the list
    $List = $Web.Lists[$ListName]

    #Get the new content type
    $NewContentType = $List.ContentTypes[$NewContentTypeName]
 
    #Checkin any checked out file 
    foreach($item in $list.Items)
    {
        if($item.File.CheckOutStatus -ne "None")
        {
            #check file in            
            $item.File.CheckIn("Checked In By Administrator") 
            write-host "Checked-out file checked-in on item: "$item.id
        }
    }

    #Iterate through each item in the list 
    foreach($item in $list.Items)
    {
        if($item.ContentType.Name -eq $OldContentTypeName)
        {        
            #Change the content type
            $item.File.CheckOut()
            $item["ContentTypeId"] = $NewContentType.Id
            $item.SystemUpdate()
            $item.File.CheckIn("Content type changed to " + $NewContentType.Name, 1)
            Write-host "Content type changed for item: "$item.id
        }
    }
}

#Variables for processing
$WebURL ="http://sales.crescent.com"
$ListName ="Q1 Sales Proposals"
$ContentTypeName ="Sales Proposal"

#Get the Web and List
$Web = Get-SPWeb $WebURL
$List = $Web.lists.TryGetList($ListName)

if($list -ne $null)
{
    #Call the function to add content type
    Change-ItemContentType $web $list "document" "Sales Proposal"
}

This will change the old content type “document” of all documents to a new content type ‘Sales Proposal’. Next time, when users edit the documents, they’ll be prompted to enter required fields from the new content type.

Here is my another post for SharePoint Online: PowerShell for SharePoint Online to Change Content Type

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

6 thoughts on “Change Content Type of Existing Items in SharePoint using PowerShell

  • September 24, 2019 at 1:28 AM

    How to change content type of documents in SharePoint in all versions of it

    Reply
  • May 22, 2019 at 11:28 AM

    Hello, first good job!
    I have a question: This scenario is specific to a list or library. Is it possible to perform for the entire Site Collection?
    Another detail: We deal with the change from “Document” to “Sales Proposal”. I ask, can I include more parameters? For example:
    Do I need to change the content types that are “Document” or “Proposals” or “Files” to “Sales Proposal”?

    Thank you and regards from Portugal.

    Rafael SharePoint

    Reply
    • May 22, 2019 at 11:59 AM

      1. You can iterate through each list from the site collection, as:
      #Iterate through All webs of the site collection
      Get-SPSite “http://your-sitecoll-url” | Get-SPWeb -Limit All | ForEach-Object

      #Iterate through All Lists
      Foreach ($List in $_.Lists)
      {
      #Do something here
      }

      2. Yes, Add more parameters to the function and use “OR” operator to check
      If($item.ContentType.Name -eq $OldContentTypeName1 or $item.ContentType.Name -eq $OldContentTypeName2 or $item.ContentType.Name -eq $OldContentTypeName3)
      {
      #Do something here
      }

      Reply
  • October 10, 2017 at 4:18 PM

    Probably with Patterns and practises.

    Reply
  • July 25, 2015 at 10:50 PM

    Is there any way to do this in SharePoint online?

    Reply

Leave a Reply