Change Content Type With PowerShell


Change the content type of many files in a single library.


Use the following PowerShell script to change the content type instead of editing each file one at a time. In my example, I change the content type from “Document” to “Process”.

function Reset-SPFileContentType ()
#Get web, list and content type objects
$web = Get-SPWeb -Identity http://spsite
$list = $web.Lists["Documents"]
$oldCT = $list.ContentTypes["Document"]
$newCT = $list.ContentTypes["Process"]
$newCTID = $newCT.ID

#Check if the values specified for the content types actually exist on the list
if (($oldCT -ne $null) -and ($newCT -ne $null))
#Go through each item in the list
$list.Items | ForEach-Object {
#Check if the item content type currently equals the old content type specified
if ($_.ContentType.Name -eq $oldCT.Name)
#Check the check out status of the file
if ($_.File.CheckOutType -eq "None")
#Change the content type association for the item
write-host "Resetting content type for file" $_.Name "from" $oldCT.Name "to" $newCT.Name
$_["ContentTypeId"] = $newCTID
$_.File.CheckIn("Content type changed to " + $newCT.Name, 1)
write-host "File" $_.Name "is checked out to" $_.File.CheckedOutByUser.ToString() "and cannot be modified"
write-host "File" $_.Name "is associated with the content type" $_.ContentType.Name "and shall not be modified"
write-host "One of the content types specified has not been attached to the list"$list.Title

Credit to Phil Childs’ article for SharePoint 2010. The script also works for SP 2013. 


2 thoughts on “Change Content Type With PowerShell

  1. Excellent post. I was checking constantly this blog and I’m inspired! Extremely helpful info specifically the last phase 🙂 I handle such information a lot. I was looking for this particular info for a very long time. Thanks and good luck.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s